Made some changes to the getPatchCandidates() method:

Removed the DeviceID as the index, because it was forcing DeviceID sort order.
Split the SQL into two statements so that we can get all of the devices in the current cabinet first, followed by all of the devices not in the same cabinet (in Lexicographical order).