LCDial application can be called in the Asterisk dialplan to get a least cost routing / failover implementation to route phone calls to the least cost provider.
For example, you can get one phone termination with the best price for land calls, and another one for mobile calls.
It uses 2 tables in the MySQL database, one with the list of phone termination providers, and one to define the cost, per provider, for each prefix.
LCDial() app will call Dial() app passing the technology/resource parameter for the least cost provider: if Dial() fails, it will be called again (and again) using another provider, until Dial() return SUCCESS.
The current version works with Asterisk versions up to 16.1.x. , and has been tested with Asterisk 14, Asterisk 11, Asterisk 1.8, Asterisk 1.6, Asterisk 1.4.
This is free software: you can use it as you prefer, in respect to the GNU Public License.