use the AXL executeSQLQuery (Can't remember the method name exactly) to run the following query:
select a.name from device a, numplan b, devicenumplanmap c
where a.pkid = c.fkdevice
and b.pkid = c.fknumplan
and b.dnorpattern = '12345'
that will return the name of all devices that have the extension 12345. it's also possible to expand the query so you can specify the partition, or to indicate that the number must be the first line on the phone.
c