public Rates CalculateRates(DataModule tariff, string originZip, string classCode, string discount, string floorMin, string[] destinationZips) { //Calcualate rates string[] WEIGHT_RANGES = { "1", "501", "1001", "2001", "5001", "10001", "20001" }; Rates rates = new Rates(); try { for (int i = 0; i < destinationZips.Length; i++) { LTLRateShipmentRequest[] requests = new LTLRateShipmentRequest[WEIGHT_RANGES.Length]; for (int j = 0; j < WEIGHT_RANGES.Length; j++) { LTLRateShipmentRequest request = new LTLRateShipmentRequest(); request.tariffName = tariff != null ? tariff.tariffName : ""; request.shipmentDateCCYYMMDD = tariff != null ? tariff.effectiveDate : ""; request.originPostalCode = originZip; request.destinationPostalCode = destinationZips[i]; request.destinationCountry = request.originCountry = "USA"; request.useSingleShipmentCharges = "N"; request.rateAdjustmentFactor = "1.0000"; request.useDiscounts = "Y"; request.discountApplication = "R"; //Apply discount to R=Rates, C=Charges request.mcDiscount = discount; request.userMinimumChargeFloor = floorMin; request.LTL_Surcharge = "0"; request.TL_Surcharge = "0"; request.surchargeApplication = "G"; //Apply surcharge to G=Gross, N=Net LTLRequestDetail detail = new LTLRequestDetail(); detail.nmfcClass = classCode; detail.weight = WEIGHT_RANGES[j].ToString(); request.details = new LTLRequestDetail[] { detail }; requests[j] = request; } LTLRateShipmentResponse[] responses = new RateWareGateway().CalculateLTLRates(requests); ////Take lesser of min charge from rate ware or set floor min //double minCharge = Convert.ToDouble(responses[0].minimumCharge); //if (minCharge < floorMin) minCharge = floorMin; //Add rates to the grid RateQuoteDataset.RateTableRow _rate = new RateQuoteDataset().RateTable.NewRateTableRow(); _rate.OrgZip = responses[0].originPostalCode; _rate.DestZip = responses[0].destinationPostalCode.Substring(0, 3); _rate.MinCharge = responses[0].minimumCharge; _rate.Rate1 = responses[0].details[0].rate; _rate.Rate501 = responses[1].details[0].rate; _rate.Rate1001 = responses[2].details[0].rate; _rate.Rate2001 = responses[3].details[0].rate; _rate.Rate5001 = responses[4].details[0].rate; _rate.Rate10001 = responses[5].details[0].rate; _rate.Rate20001 = responses[6].details[0].rate; rates.Add(new Rate(_rate)); } } catch (Exception ex) { throw new FaultException <RateQuoteFault>(new RateQuoteFault(ex.Message), "Service Error"); } return(rates); }
private void OnFormLoad(object sender, EventArgs e) { //Event handler for form load event try { //Set control defaults #region Grid customizations from normal layout (to support cell editing) this.grdRates.DisplayLayout.Bands[0].Override.RowFilterMode = RowFilterMode.AllRowsInBand; #endregion //Get all tariffs and create dataset schema this.mRates = new DataSet(); this.mRates.Tables.Add("LTLRatesTable"); this.mRates.Tables["LTLRatesTable"].Columns.Add("Origin"); this.mRates.Tables["LTLRatesTable"].Columns.Add("Destination"); this.mRates.Tables["LTLRatesTable"].Columns.Add("NMFC"); this.mRates.Tables["LTLRatesTable"].Columns.Add("Weight"); DataModule[] tariffs = FinanceGateway.GetAvailableTariffs(); for (int k = 0; k < tariffs.Length; k++) { this.mRates.Tables["LTLRatesTable"].Columns.Add(tariffs[k].effectiveDateField); } this.mRates.Tables["LTLRatesTable"].Columns.Add("PSP"); this.mRates.AcceptChanges(); //Loop thru all delivery locations DataSet destinations = FinanceGateway.ViewDeliveryZips(); DataRow row = null; //for(int j = 0; j < destinations.Tables["DeliveryZipTable"].Rows.Count; j=j+100) { for (int j = 0; j < 5; j++) { //Get an LTL rate for each tariff for this destination row = this.mRates.Tables["LTLRatesTable"].NewRow(); row["Origin"] = "07657"; row["Destination"] = destinations.Tables["DeliveryZipTable"].Rows[j]["Zip"].ToString(); row["NMFC"] = "50"; row["Weight"] = "1500"; for (int i = 0; i < tariffs.Length; i++) { //Setup the request for NMFC=50, weight=100lbs, Origin=Ridgefield DataModule tariff = tariffs[i]; LTLRateShipmentSimpleRequest request = new LTLRateShipmentSimpleRequest(); request.tariffNameField = tariff != null ? tariff.tariffNameField : ""; request.shipmentDateCCYYMMDDField = tariff != null ? tariff.effectiveDateField : ""; request.destinationCountryField = request.originCountryField = "USA"; request.originPostalCodeField = "07657"; request.destinationPostalCodeField = destinations.Tables["DeliveryZipTable"].Rows[j]["Zip"].ToString(); LTLRequestDetail detail = new LTLRequestDetail(); detail.nmfcClassField = "50"; detail.weightField = "1500"; request.detailsField = new LTLRequestDetail[] { detail }; //Get the LTL rate and add a datarow LTLRateShipmentSimpleResponse response = FinanceGateway.CalculateLTLSimpleRate(request); row[tariff.effectiveDateField] = response.totalChargeField; } //Get the PSP rate for this destination LTLQuote2 quote = new LTLQuote2(); quote.ShipDate = DateTime.Today; quote.OriginZip = "07657"; quote.DestinationZip = destinations.Tables["DeliveryZipTable"].Rows[j]["Zip"].ToString(); quote.Pallet1Weight = 100; quote = FreightGateway.CreateQuote(quote); row["PSP"] = quote.TotalCharge.ToString(); //Ad the results for this destination this.mRates.Tables["LTLRatesTable"].Rows.Add(row); } this.grdRates.DataSource = this.mRates; this.grdRates.DataMember = "LTLRatesTable"; } catch (Exception ex) { App.ReportError(ex, true, LogLevel.Error); } }