VoIP Numbers automatic selection

Hi all!

I’ve booked 3 VoIP numbers and i’ve embedded them into my asterisk configuration (sip.conf) in this way:

register => user1:pwd1@voipprovider.it:number1
register => user2:pwd2@voipprovider.it:number2
register => user3:pwd3@voipprovider.it:number3

[number1]
username=user1

[number2]
username=user2

[number3]
username=user3

For my system scope, i work with outbound call files like this:

my.call
Channel: SIP/55565543@number1
Context:IVR

I want to produce a “dynamic” call file: in other words, if the number1 is busy, i want that the call file will be like this:
my.call
Channel: SIP/55565543@number2
Context:IVR

My idea is to make a channel scan (something similar to sip show channels), and select the free trunk (associated to number2 in my example) but i don’t know if it’s the best solution and how to implement it in the best way.

Can you suggest me a better way to proceed?

Thanks in advance!
Mario