Outgoing calls on multiple sip lines

I have various sip lines and I want to make my outgoing calls trying to dial the first available line. To accomplish this I have the following entries in the AstDB

SIPLINES/line1 : line_name_1
SIPLINES/line2 : line_name_2
.
.
and so on…

and the following code in extensions.conf:

[macro-dial_all]
;
; Dial all macro:
; This macro is used when there are more than one sip lines defined and it
; will try to dial out the first available line.
;
; ${ARG1} - Dialed number
;
exten => s,1,NoOp(${ARG1})
exten => s,n,Set(dialnum=${ARG1})
exten => s,n,Goto(s-DOUT,1)

exten => s-DOUT,1,Set(DBKEY=0)
exten => s-DOUT,n(increment),Set(DBKEY=$[${DBKEY} + 1])
exten => s-DOUT,n,DBget(TRUNK=SIPLINES/line${DBKEY})
exten => s-DOUT,n,GotoIf($[“foo${TRUNK}” = “foo”]?s-GIVEUP,1)
exten => s-DOUT,n,Dial(SIP/${dialnum}@${TRUNK}|20)
exten => s-DOUT,n,Goto(s-${DIALSTATUS},1)

exten => s-CHANUNAVAIL,1,Playback(pls-wait-connect-call)
exten => s-CHANUNAVAIL,n,Goto(s-DOUT,increment)
exten => s-BUSY,1,Playback(pls-wait-connect-call)
exten => s-BUSY,n,Goto(s-DOUT,increment)
exten => s-CONGESTION,1,Playback(pls-wait-connect-call)
exten => s-CONGESTION,n,Goto(s-DOUT,increment)
exten => s-NOANSWER,1,Playback(pls-wait-connect-call)
exten => s-NOANSWER,n,Goto(s-DOUT,increment)

exten => s-GIVEUP,1,Playback(all-outgoing-lines-unavailable)
exten => s-GIVEUP,n,Playback(please-try-again-later)
exten => s-GIVEUP,n,Congestion()
exten => s-GIVEUP,n,Hangup()

It works well but I have this problem: For example, when I dial a number the system will try to dial the first sipline in the AstDB but if the line is busy or unavailable I have to wait that the ringtime expires (20 s in this case) before it tries to dial the next sipline. I want the system to try the next sip line immediately when it receives a busy response from the first line.

Thanks in advance.

It seems you are taking the complicated route. All I do is set qualify=2000 under my trunks so this way Asterisk is constantly making sure that the route is up. I then try to use the first route. If it does not work it rolls over to the second one.

exten => _X.,1,Dial(SIP/${EXTEN}@provider-1,20)
exten => _X.,2,Hangup
exten => _X.,102,Dial(SIP/${EXTEN}@provider-1,20)
exten => _X.,103,Hangup