After randomising the ballasts, the controller searches for the ballast with the lowest random number. It does this by issuing search address commands which contain the address that it is looking for, and compare commands which are queries, which get replies from all the ballasts that have that search address or lower as their random address.
Once the controller gets no replies, it backtracks one step to check the one ballast with that random address, then it assigns it a short address using a special program command which only takes effect in the ballast whose random address equals the search address. (This is technically called the "selected" state). Then the controller tells that ballast to withdraw from the process so it doesn't respond to further compares this time round, and the search can continue for the next highest ballast.
The standards don't actually dictate that binary search is the algorithm used, but it is assumed that this the best method. Note that some people use the term "long address" but this is not the correct name, there is only the random address and the search address (the current value guessed by the controller), and that the random address is not really an address mode of the commands (which are too short to contain it anyway). There is only 267 Program Short Address and 269 Query Short address commands that use the random/search address as the defining factor as to whether the command applies to them, and these are only valid between Initialise and Terminate.
There are many small details to this process which I have omitted for simpilicity, like dealing with duplicate random addresses, but this gives you the general idea.
Once the controller has identified one ballast by search address, it is free to chose a short address. Some controllers do this automatically, others allow the user to enter the number they would like to use. It is usual at this point to identify which ballast has been found by means of flashing the lamps, using the short address.
As you have found out, Command 269 Query Short Address only works if the gear is physically selected or the random address is equal to the search address, and only while the 15 minute initialise timer is running. This command is to be used during addressing. At other times, you can use any query which is sent using short addressed addressing to see if you get a response. Typically systems will use Command 145 Query Control Gear to see if there is a gear at that address. You may find it preferable to use Command 153 Query Device Type since you get a response that tells you more than whether there is a gear at that address, it tells you the type. Although there is Command 150 Query Missing Short Address, this would be no more useful in this situation than the other queries I mentioned if you sent it using short addressed mode, it is generally more useful in broadcast mode with only one gear on the line.
With any of these queries, you have to scan through all possible short addresses to see if you get a response. I would not recommend stopping as soon as you find a No because there is no requirement in DALI to keep the short addresses adjacent with no gaps.
Best Answer
Yes it can be done. You have to send 3 forward frames
Command 257 SET DTR (binary 1010 0011 1111 1111) which has value 0xFF (sets DTR to 0xFF which is MASK)
Command 128 STORE DTR AS SHORT ADDRESS (binary YAAA AAA1 1000 0000), repeated twice within 100ms.
Command 257 is not addressed, so will be processed by all the gear on the bus. The way you apply it to only some of the gear is by setting the address in Command 128. So you can delete the short address in all gear (broadcast), only those in a particular group (group addressed) or only those/that one with a short address. Many commands use DTR this way, so you should not rely on a previously set DTR value before sending your configuration command; the DTR is likely to change frequently.
Y=1 means group address or broadcast. 0 means A bits are short address
A bits are the binary of 0 to 63 for short address, 0-15 for group address, all 1s for broadcast.