Hi MK M,
How the system determines the leg for a shipment depends on the leg categories you defined in your shipment type.
Refer to the below for the different categories available:
http://help.sap.com/erp2005_ehp_05/helpdata/EN/93/743f46546011d1a7020000e829fd11/frameset.htm
Refer to the below for the automatic leg determination process flow:
http://help.sap.com/erp2005_ehp_05/helpdata/EN/93/743f00546011d1a7020000e829fd11/frameset.htm
Refer to the below for examples of automatic leg determination:
http://help.sap.com/erp2005_ehp_05/helpdata/EN/93/743f27546011d1a7020000e829fd11/frameset.htm
Regards,
Enrique