/// <summary> /// Adds newgistics style parcel to the Shipment. /// </summary> /// <returns>The parcel.</returns> /// <param name="f">Fluent object.</param> /// <param name="p">Parcel to add</param> /// <typeparam name="T">IShipment concrete type.</typeparam> /// <typeparam name="O">IShipmentOptions concrete type.</typeparam> public static ShipmentFluent <T> NewgisticsParcel <T, O>( this ShipmentFluent <T> f, IParcel p ) where T : class, IShipment, new() where O : class, IShipmentOptions, new() { f.Parcel(p); if (p.Dimension.IrregularParcelGirth > 0) { T shipment = f; foreach (var o in shipment.ShipmentOptions) { if (o.ShipmentOption == ShipmentOption.IS_RECTANGULAR) { o.Value = "false"; return(f); } } var rectOpt = new O { ShipmentOption = ShipmentOption.IS_RECTANGULAR, Value = "false" }; } return(f); }
//PCA from JLB public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segment, int sampleSize, ITourWrapper tour, ITripWrapper trip, IParcel chosenParcel) { _choiceProbabilityCalculator = choiceProbabilityCalculator; _segmentZones = Global.SegmentZones[segment]; _sampleSize = sampleSize; _tourOriginParcel = tour.OriginParcel; _tourOriginSegmentZone = _segmentZones[_tourOriginParcel.ZoneId]; _tripOriginParcel = trip.OriginParcel; _tripOriginSegmentZone = _segmentZones[_tripOriginParcel.ZoneId]; if (_tourOriginParcel == null || _tripOriginSegmentZone == null) { } if (chosenParcel != null) { _chosenParcel = chosenParcel; _chosenSegmentZone = _segmentZones[chosenParcel.ZoneId]; } if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { throw new ChosenParcelNotSetInEstimationModeException(); } }
// public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segment, int sampleSize, IParcel originParcel, IParcel excludedParcel, IParcel chosenParcel) { // _choiceProbabilityCalculator = choiceProbabilityCalculator; // _segmentZones = Global.SegmentZones[segment]; // _sampleSize = sampleSize; // // _originParcel = originParcel; // _originSegmentZone = _segmentZones[originParcel.ZoneId]; // // if (excludedParcel != null) { // _excludedParcel = excludedParcel; // _excludedSegmentZone = _segmentZones[excludedParcel.ZoneId]; // } // // if (chosenParcel != null) { // _chosenParcel = chosenParcel; // _chosenSegmentZone = _segmentZones[chosenParcel.ZoneId]; // } // // if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { // throw new ChosenParcelNotSetInEstimationModeException(); // } // } public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segment, int sampleSize, IParcel originParcel, IParcel excludedParcel, IParcel usualParcel, IParcel chosenParcel) { _choiceProbabilityCalculator = choiceProbabilityCalculator; _segmentZones = Global.SegmentZones[segment]; _sampleSize = sampleSize; _originParcel = originParcel; _originSegmentZone = _segmentZones[originParcel.ZoneId]; if (excludedParcel != null) { _excludedParcel = excludedParcel; _excludedSegmentZone = _segmentZones[excludedParcel.ZoneId]; } if (usualParcel != null) { _usualParcel = usualParcel; _usualSegmentZone = _segmentZones[usualParcel.ZoneId]; } if (chosenParcel != null) { _chosenParcel = chosenParcel; _chosenSegmentZone = _segmentZones[chosenParcel.ZoneId]; } if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { throw new ChosenParcelNotSetInEstimationModeException(); } }
public void Add(IParcel parcel) { if (parcel != null) { _parcelDetails.Add(parcel.GetParcelDetails()); } }
public void CreateParcelsCorrectly(int dimensions, bool speedyShipping, decimal weight, decimal orderCost) { IParcelFactory parcelFactory = new ParcelFactory(); IParcel parcel = parcelFactory.CreateParcel(dimensions, speedyShipping, weight); Assert.Equal(parcel.OrderCost, orderCost); }
private static TWrapper CreateWrapper(IParcel parcel) { var type = typeof(TWrapper); var instance = Activator.CreateInstance(type, parcel); return((TWrapper)instance); }
public bool IsPackageFitParcel(IPackage package, IParcel parcel) { if (!parcel.ValidateParcel()) { return(false); } return(parcel.Height <= package.MaxHeight && parcel.Length <= package.MaxLength && parcel.Breadth <= package.MaxBreadth && parcel.Weight <= package.MaxWeight); }
ParcelCosting CalculateParcelCost(IParcel parcel) { var parcelCostings = ParcelCostings .Where(c => ValidParcelCosting(parcel, c)) .Select(c => MakeParcelCosting(parcel, c)) .OrderBy(c => c.ParcelCost); return(parcelCostings.FirstOrDefault()); }
public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segmentZonesIndex, int sampleSize, IParcel chosenParcel, IParcel originParcel) : this(choiceProbabilityCalculator, segmentZonesIndex, sampleSize, chosenParcel) { _originParcel = originParcel; _originSegmentZone = _segmentZones[originParcel.ZoneId]; //JLB 20120329 removed these lines because usual work location model doesn't set a sampled dest to chosen when it is the residence location // if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { // throw new ChosenParcelNotSetInEstimationModeException(); // } }
public IParcel Process(IParcel parcelInstance) { if (parcelInstance.Value > 1000) { parcelInstance.NeedSignOff = true; } _nextInChain.Process(parcelInstance); return(parcelInstance); }
private const int NULL_DESTINATION_ERROR = NULL_DESTINATION_WARNING * 10; //MUST BE A MULTIPLE OF NULL_DESTINATION_WARNING private DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segmentZonesIndex, int sampleSize, IParcel chosenParcel) { _choiceProbabilityCalculator = choiceProbabilityCalculator; _segmentZonesIndex = segmentZonesIndex; _segmentZones = Global.SegmentZones[_segmentZonesIndex]; _sampleSize = sampleSize; if (chosenParcel != null) { _chosenParcel = chosenParcel; _chosenSegmentZone = _segmentZones[chosenParcel.ZoneId]; } }
public IParcel Process(IParcel parcelInstance) { if (parcelInstance.Weight <= 1) { parcelInstance.Department = Models.Departments.Mail; } else { _nextInChain.Process(parcelInstance); } return(parcelInstance); }
public IParcel Process(IParcel parcelInstance) { if (parcelInstance.Weight > 1 && parcelInstance.Weight <= 10) { parcelInstance.Department = Models.Departments.Regular; } else { _nextInChain.Process(parcelInstance); } return(parcelInstance); }
public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segmentZonesIndex, int sampleSize, IParcel chosenParcel, ITourWrapper tour, ITripWrapper trip) : this(choiceProbabilityCalculator, segmentZonesIndex, sampleSize, chosenParcel) { _tourOriginParcel = tour.OriginParcel; _tourOriginSegmentZone = _segmentZones[_tourOriginParcel.ZoneId]; _tripOriginParcel = trip.OriginParcel; _tripOriginSegmentZone = _segmentZones[_tripOriginParcel.ZoneId]; if (_tourOriginParcel == null || _tripOriginSegmentZone == null) { } if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { throw new ChosenParcelNotSetInEstimationModeException(); } }
public DestinationSampler(ChoiceProbabilityCalculator choiceProbabilityCalculator, int segmentZonesIndex, int sampleSize, IParcel chosenParcel, IParcel originParcel, IParcel excludedParcel, IParcel usualParcel) : this(choiceProbabilityCalculator, segmentZonesIndex, sampleSize, chosenParcel, originParcel) { if (excludedParcel != null) { _excludedParcel = excludedParcel; _excludedSegmentZone = _segmentZones[excludedParcel.ZoneId]; } if (usualParcel != null) { _usualParcel = usualParcel; _usualSegmentZone = _segmentZones[usualParcel.ZoneId]; } if (_choiceProbabilityCalculator.ModelIsInEstimationMode && chosenParcel == null) { throw new ChosenParcelNotSetInEstimationModeException(); } }
ParcelCosting MakeParcelCosting(IParcel parcel, ParcelCostingParameters costParams) { var result = new ParcelCosting { Parcel = parcel, CostingType = costParams.CostingType, ParcelCost = costParams.BaseCost }; var overweight = parcel.Weight - costParams.MaxWeight; if (overweight > 0) { result.ParcelCost += Math.Ceiling(overweight) * costParams.CostPerExtraKg; } return(result); }
public IPackage MatchParcelPackage(IParcel parcel) { IPackage targetPackage = null; foreach (var p in ListPackage().OrderBy(l => l.Price)) { if (IsPackageFitParcel(p, parcel)) { targetPackage = p; break; } } if (targetPackage == null) { new LogManager().Log($"MatchParcelPackage(). Unable to find a matching package for parcel({parcel.Length}*{parcel.Height}*{parcel.Breadth} {parcel.Weight}kg)"); } else { new LogManager().Log($"MatchParcelPackage(). Package {targetPackage.PackageTypeName}(${targetPackage.Price}) is used for parcel({parcel.Length}*{parcel.Height}*{parcel.Breadth} {parcel.Weight}kg)"); } return(targetPackage); }
public ParcelWrapper(IParcel parcel) { m_parcel = parcel; }
bool AllParcelDimensionsLessThan(IParcel parcel, decimal maxDimension) => parcel.Height < maxDimension && parcel.Width < maxDimension && parcel.Depth < maxDimension;
bool ValidParcelCosting(IParcel parcel, ParcelCostingParameters costParams) => !costParams.DimensionsMax.HasValue || AllParcelDimensionsLessThan(parcel, costParams.DimensionsMax.Value);
public void IsParcelLimitStatus() { IParcel smallParcel = ParcelFactoryHelper.CreateParcel(2, 1, 1, 51); Assert.IsTrue(smallParcel.IsParcelLimit); }
public ParcelWrapper(IParcel parcel) : base(parcel) { _parcel = (IParcel)parcel; }
public decimal Calculate(IParcel parcel) { return(parcel.DeliveryUnitCost * parcel.Dimension.Weight); }
private TSampleItem GetDestination <TSampleItem>(RandomUniform01 randomUniform01, IParcel originParcel, SegmentZone originSegmentZone, IParcel excludedParcel, SegmentZone excludedSegmentZone) where TSampleItem : ISampleItem, new() { int destinationZoneId = 0; SegmentZone destinationSegmentZone = null; int destinationParcelSequence = 0; int destinationParcelId = 0; bool destinationParcelIsValid = false; double random = randomUniform01.Uniform01() * originSegmentZone.TotalWeight; if (random > .001) { double total = 0D; // draw the zone foreach (WeightSegmentItem weight in originSegmentZone.RankedWeights) { total += weight.Value; if (total <= random) { continue; } destinationZoneId = weight.Id; destinationSegmentZone = _segmentZones[weight.Id]; break; } } if (destinationSegmentZone != null && destinationSegmentZone.Key == 0) { } if (destinationSegmentZone == null) { destinationZoneId = originParcel.ZoneId; destinationSegmentZone = originSegmentZone; } double excludedSize = 0D; if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.Parcel) { if (destinationZoneId == originParcel.ZoneId) { excludedSize += originSegmentZone.GetSize(originParcel.Sequence); } if (excludedParcel != null && destinationZoneId == excludedParcel.ZoneId) { excludedSize += excludedSegmentZone.GetSize(excludedParcel.Sequence); } } if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.Zone) { if (destinationSegmentZone.Key == 0) { } destinationParcelId = destinationSegmentZone.Key; destinationParcelSequence = 0; destinationParcelIsValid = true; } else { // if (destinationSegmentZone.TotalSize - excludedSize < Constants.EPSILON) { // Console.WriteLine(originSegmentZone.Id); // Console.WriteLine(originSegmentZone.TotalWeight); // Console.WriteLine(originSegmentZone.TotalSize); // Console.WriteLine(destinationSegmentZone.Id); // Console.WriteLine(destinationSegmentZone.TotalWeight); // Console.WriteLine(destinationSegmentZone.TotalSize); // Console.WriteLine(excludedSize); // } random = randomUniform01.Uniform01() * (destinationSegmentZone.TotalSize - excludedSize); if (random > .001) { double total = 0D; // draw the parcel within zone foreach (SizeSegmentItem size in destinationSegmentZone.RankedSizes) { if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.MicroZone || (originParcel.Id != size.Id && (excludedParcel == null || excludedParcel.Id != size.Id))) { total += size.Value; } if (total <= random) { continue; } // don't include the drawn parcel if the parcel has no size if (size.Value >= Global.Configuration.MinParcelSize) { destinationParcelId = size.Id; destinationParcelSequence = size.Sequence; destinationParcelIsValid = true; } break; } } } if (Global.Configuration.DestinationScale != Global.Settings.DestinationScales.Zone && !destinationParcelIsValid) { return(default(TSampleItem)); } TSampleItem sampleItem = new TSampleItem(); sampleItem.Initialize(this, destinationParcelId, destinationParcelSequence, destinationSegmentZone); if (destinationParcelIsValid) { sampleItem.ExcludedSize = excludedSize; } return(sampleItem); }
public ParcelWrapper(IParcel parcel) { _parcel = parcel; }
public IDelivery NewDelivery(object id, decimal cost, object currency, string type, IAddress source, IAddress destination, IPickPoint pickPoint, IParcel parcel) { throw new System.NotImplementedException(); }
public IEnumerable<IParcelRate> GetRates(IParcel package) { _lastRequest = GenerateRequest(package); _lastResponse = SendRequest(_lastRequest); return ParseResponse(_lastResponse); }
public void Add(IParcel parcel) { _parcels.Add(parcel); }
/// <summary> /// REQUIRED. Contains physical characteristics of the parcel. /// </summary> /// <param name="p"></param> /// <returns></returns> public ShipmentFluent <T> Parcel(IParcel p) { _shipment.Parcel = p; return(this); }
public void AddParcelToOrder(IParcel parcel) { this.Parcels.Add(parcel); }
IParcelWrapper IParcelCreator.CreateWrapper(IParcel parcel) { return(CreateWrapper(parcel)); }
/// <summary> /// Create an XML request to send to USPS. /// </summary> /// <param name="parcel"></param> /// <returns></returns> private XElement GenerateRequest(IParcel parcel) { // Create an XML request from the values in package XElement request = new XElement("RateV4Request"); request.SetAttributeValue("USERID", _userID); XElement revision = new XElement("Revision", "2"); request.Add(revision); XElement package = new XElement("Package"); package.SetAttributeValue("ID", "1"); XElement serviceType = new XElement("Service", parcel.ShipMethod); package.Add(serviceType); // If we use a First Class service, we must include a type if (parcel.ShipMethod == "FIRST CLASS") { XElement firstClassType = new XElement("FirstClassMailType", parcel.ContainerType); package.Add(firstClassType); } XElement origin = new XElement("ZipOrigination", _originationZIP); package.Add(origin); XElement destinationZIP = new XElement("ZipDestination", parcel.DestinationZip); package.Add(destinationZIP); XElement pounds = new XElement("Pounds", parcel.Pounds); package.Add(pounds); XElement ounces = new XElement("Ounces", parcel.Ounces); package.Add(ounces); if (parcel.IsOverSize) { // Is the package rectangular? string shape = parcel.IsOddShape ? "NONRECTANGULAR" : "RECTANGULAR"; XElement container = new XElement("Container", shape); package.Add(container); XElement size = new XElement("Size", "LARGE"); package.Add(size); // We need our dimensions XElement width = new XElement("Width", parcel.Width); package.Add(width); XElement length = new XElement("Length", parcel.Length); package.Add(length); XElement height = new XElement("Height", parcel.Height); package.Add(height); if (parcel.IsOddShape) { XElement girth = new XElement("Girth", parcel.Girth); package.Add(girth); } } else { XElement container = new XElement("Container"); package.Add(container); XElement size = new XElement("Size", "REGULAR"); package.Add(size); } XElement value = new XElement("Value", "1500"); package.Add(value); XElement machinable = new XElement("Machinable", parcel.IsMachinable); package.Add(machinable); //XElement services = new XElement("SpecialServices"); //XElement special = new XElement("SpecialService", "1"); //services.Add(special); //package.Add(services); request.Add(package); return request; }
public IDeliveryRequest NewDeliveryRequest(IAddress sourceAddress, IAddress destinationAddress, object deliveryType, IParcel parcel, object currency) { throw new System.NotImplementedException(); }