My understanding of the question was also that one. And I haven't response.
The least we can assume is that the client game contains (at least) 2 subroutines to insert an item into the player's bags.
One is used when an item is looted (automatically distributed in a party or picked off the ground), this method looks for any items with same type, typeID and stack the new item(s) in the current stack if the 'count' limit is not reached (or it create a new stack).
The second is used duriong trade with other player, purchase from NPC, receiving of quest reward and receiving item generated by a fortune bag (item with special field settled to 42), for all these cases the method looks for the first available (empty) slot.
Both likely end with a notification trame sent to the server to let it know that the item was stored in slot 'S' of bag 'B', if one is able to set a breakpoint at this point and them trace thru t-he calling code, may be it could be possible to change the second method to call the first one instead. But may be the initial assumption is incorrect.