Hi Ibrahim,
As per your requirement. You have to select Warehouse based on Expiry date, Batchnum and Qty.
Let say you have an item with given scenario as mentioned in Snap shot.
Image may be NSFW.
Clik here to view.
In Snap Shot you have 3 batches with different quantity and different expiry date. Now you have to choose warehouse based on expiry date. In this you'll use warehouse CN-DS which having expiry date earlier than other batches. Please let me know If I am wrong.
Now what you have to do you have use given FMS which should have warehouse ordered by ExpiryDate, Batch and Qunatity in case of Sales Order. You have to change this query if you do Issue for Production or Good Issue...
Select A.Whscode,B.ExpDate,B.DistNumber,A.Quantity from OBTQ A inner Join OBTN B on A.SysNumber=B.SysNumber and A.ItemCode=B.ItemCode and A.AbsEntry=B.AbsEntry where A.ItemCode=$[$38.1.1] and A.Quantity>0
Order By B.ExpDate,A.WhsCode,B.DistNumber,A.Quantity
For More details Please refer Screen Shot of Sales Order...