Help with call-limit

After hours of research this still confuses me, so I hope you can help, we have 4 broadvoice lines that go out, and 2 sipura 2002’s that connect them to our analog PBX, How can I set it up so that when a number is dialed out it will pick the first available BV line that has less then 1 calls, and when inbound calls come in, it will ring on the first extension that has less then 1 call (the ATAs are SIP/400 through 404)