Issue while creating New Reservation

I am getting attached error while creating New Reservation document by using below mentioned code. Though IsSavable is true it means I am passing all expected values. Please advise.

private static void NewShipment()
{
StockingLocationOrganization locations = StockingLocationOrganization.GetOrganization(ActiveStatus.Active);
List oList = locations.GetStockingLocationIDList();
Guid FromStockingLocationID = Guid.Empty;
Guid ToStockingLocationID = Guid.Empty;
foreach (var item in oList)
{
FromStockingLocationID = item;
}

        StockingLocationList jobs = StockingLocationList.GetJobsites(false, JobTreeNodeDisplayType.Name, Guid.Empty);

        foreach (StockingLocationListItem job in jobs)
        {
            if(job.Name == "0207- Al Jaddaf")
            { ToStockingLocationID = job.TradingPartnerID;}
        }

        Shipment ship = Shipment.NewShipment(ShipmentStatusType.NewReservation);
        ship.FromLocationType = SourceType.BranchOffice;
        ship.FromStockingLocationID = FromStockingLocationID;
        ship.ToLocationType = SourceType.JobSite;
        ship.ToStockingLocationID = ToStockingLocationID;
        ship.ShipmentProducts["23-005-05", Guid.Empty].ReservedQuantity = 100;
        ship.PlannedShipDate = new DateTime(2015, 9, 19).ToShortDateString();
        if (ship.IsSavable)
        { ship.Save(); }
    }

Hi.

The exception thrown is an SQL Foreign Key one, basically meaning that the ToStockingLocationID is not valid - couldn’t be found in the StockingLocation table. Below is a working code to do the same -

            Shipment ship = Shipment.NewShipment(ShipmentStatusType.NewReservation);
            ship.FromLocationType = SourceType.BranchOffice;
            ship.ToLocationType = SourceType.JobSite;
            ship.FromStockingLocationID = TradingPartner.GetTradingPartner("branch-name").StockingLocationID;
            ship.ToStockingLocationID = TradingPartner.GetTradingPartner("job-name").StockingLocationID;
            ship.ShipmentProducts["part-number", Guid.Empty].ReservedQuantity = 25;
            ship.PlannedShipDate = DateTime.Now.ToShortDateString();
            ship.RentStartDate = DateTime.Now.ToShortDateString();
            if (ship.IsSavable)
                ship.Save(); 

Thank you for posting.