using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration ;
//using Microsoft.Web.Services2.Security ;
//using Microsoft.Web.Services2.Security.Tokens ;
//using Microsoft.Web.Services2.Security.X509 ;
using System.Xml ;
using System.Xml.Serialization ;
using System.IO ;
using System.Web.UI.HtmlControls;
using System.Text ;
using Microsoft.RFIDLab.EPCISDemo.Common ;
using Microsoft.RFIDLab.EPCISDemo.ReceivingAgentWS ;

namespace Microsoft.RFIDLab.EPCISDemo
{
	/// <summary>
	/// Performs receiver-operations.
	/// </summary>
	public class Receiver : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Button btnAcceptGoods;
		protected System.Web.UI.WebControls.HyperLink lnkPrint;
		protected System.Web.UI.WebControls.TextBox txtXml;
		protected System.Web.UI.WebControls.Button btnSendOrderCompleteNotification;
		protected System.Web.UI.WebControls.Xml Xml1;
		protected System.Web.UI.WebControls.Label lblMessage;
	
		private ASNGenerationService.Pip3B2AdvanceShipmentNotification
			objPipNotification ;
		protected System.Web.UI.WebControls.Label lblInformation;
		private static string ClientBase64KeyId =
			ConfigurationSettings.AppSettings["ClientBase64KeyId"] ;

		/// <summary>
		/// Invoked when the page loads.
		/// </summary>
		/// <param name="sender">The source of the event. </param>
		/// <param name="e">The event-arguments. </param>
		private void Page_Load ( object sender, System.EventArgs e )
		{
			objPipNotification =
				( ASNGenerationService.Pip3B2AdvanceShipmentNotification )
				Session["ASN"] ; // get the ASN from the session

			if ( objPipNotification == null )
				Response.Redirect ( "OrderDetails.aspx?session_expired=true",
					true ) ; // end if

			if ( ! IsPostBack ) // if the page is loading for the first time
			{
				// create a new XML-serializer
				XmlSerializer serializer = new XmlSerializer (
					objPipNotification.GetType () ) ;
				MemoryStream stream = new MemoryStream () ;
				// serialize the ASN into the memory-stream using the serializer
				serializer.Serialize ( stream, objPipNotification ) ;
				// get the XML string-form of the ASN
				string xml = Encoding.ASCII.GetString ( stream.ToArray () ) ;

				// if the request-mode is for printing
				if ( Request.QueryString["mode"] == "print" )
				{
					// create a new XML document and load it with the ASN
					XmlDocument doc = new XmlDocument () ;
					doc.LoadXml ( xml ) ;
					txtXml.Visible = false ; // hide the text-box
					Xml1.Visible = true ; // make the XML control visible
					Xml1.Document = doc ; // set the source-document for it
					// set the XSLT transform
					Xml1.TransformSource = "ASN.xslt" ;
					// set the properties for the print-link
					lnkPrint.Text = "Print ASN" ;
					lnkPrint.NavigateUrl = "javascript:window.print()" ;
					lnkPrint.ImageUrl = "images/printer.gif" ;

				} // end if

				else // the request-mode is not for printing
				{
					// set the properties for the print-link
					lblMessage.Text = "Accept delivery of Items from Receiving Agent." ;
					lnkPrint.Text = "Printer Friendly Version" ;
					lnkPrint.NavigateUrl = Request.Path + "?mode=print" ;
					lnkPrint.ImageUrl = "images/printer_friendly.gif" ;
					Xml1.Visible = false ; // hide the XML control
					txtXml.Visible = true ; // show the text-box
					// set the text for the text-box as the ASN
					txtXml.Text = xml ;
					txtXml.Height = 600 ; // set the height of the text-box

				} // end else

				btnSendOrderCompleteNotification.Enabled = false ;

			} // end if

		} // end of Page_Load ()

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnAcceptGoods.Click += new System.EventHandler(this.btnAcceptGoods_Click);
			this.btnSendOrderCompleteNotification.Click += new System.EventHandler(this.btnSendOrderCompleteNotification_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		/// <summary>
		/// Invoked when the 'Accept goods' button us clicked.
		/// </summary>
		/// <param name="sender">The source of the event. </param>
		/// <param name="e">The event-arguments. </param>
		private void btnAcceptGoods_Click ( object sender, System.EventArgs e )
		{
			ArrayList tagList = GetTagList () ; // get the list of tags
			object[] array = tagList.ToArray () ; // get the EPC-array
			DateTime current = DateTime.Now ; // get the current-time
			// create a proxy for the receiving-agent web-service
			ReceivingAgentWebService proxy = new ReceivingAgentWebService () ;
			// check whether security is enabled or not
			string enableSecurity =
				ConfigurationSettings.AppSettings["EnableWSSecurity"] ;

			if ( enableSecurity != null && enableSecurity.ToLower ()
				== "true" ) // if security is enabled
			{
//				X509SecurityToken token = null ;
//				X509CertificateStore store =
//					X509CertificateStore.LocalMachineStore (
//					X509CertificateStore.MyStore ) ; // local machine store
//				// retrieve the token from the store
//				token = RetrieveTokenFromStore ( store, ClientBase64KeyId ) ;
//				proxy.RequestSoapContext.Security.Tokens.Add( token );
//						proxy.RequestSoapContext.Security.Elements.Add (
//							new MessageSignature ( token ) ) ;

			} // end if

			// create a new data-base manager
			TrackTraceDBManager manager = new TrackTraceDBManager (
				TrackTraceDBManager.Constants.Receiver ) ;

			// update the status in the local data-base
			manager.AddFullEpcStatusInfo ( array,
				TrackTraceDBManager.Constants.ItemReceivedFromReceiverToReceivingAgent,
				current, objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value,
				"Receiving Agent", "Receiver Location" ) ;

			Common.OrderInformation objOrder = CreateOrderInformationObject () ;
			EquipmentProductCodeInformation objEPCEvent = new EquipmentProductCodeInformation();

			//Fillup Steward information. This is the person who 'owns' the EPC currently.
			objEPCEvent.Steward.managedBy.PartnerDescription.ContactInformation.contactName.FreeFormText.Value	= objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
			objEPCEvent.Steward.managedBy.PartnerDescription.ContactInformation.EmailAddress					= objPipNotification.toRole.PartnerRoleDescription.ContactInformation.EmailAddress ;
			objEPCEvent.Steward.managedBy.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber = objPipNotification.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
			
			objEPCEvent.CreationTimeStamp.DateTimeStamp = System.DateTime.UtcNow.ToUniversalTime().ToString("yyyyMMddThhmmss.000Z");
			objEPCEvent.BusinessTransactionIdentifier = objPipNotification.thisDocumentIdentifier.ProprietaryDocumentIdentifier;
			
			//fill up Agent information. this indicates who is sending this event.
			objEPCEvent.CurrentAgent.Agent.reportedBy.PartnerDescription.ContactInformation.contactName.FreeFormText.Value = objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
			objEPCEvent.CurrentAgent.Agent.reportedBy.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber = objPipNotification.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber;
			objEPCEvent.CurrentAgent.Agent.reportedBy.PartnerDescription.ContactInformation.EmailAddress = objPipNotification.toRole.PartnerRoleDescription.ContactInformation.EmailAddress ;

			//add EPC information.				
			objEPCEvent.EquipmentProductCodeEvent = new EquipmentProductCodeEvent[objOrder.PalletItemCollection.Count] ;
			int i = 0 ;

			foreach(Common.PalletItem pallet in objOrder.PalletItemCollection)
			{
				EquipmentProductCodeEvent objEPCEventPallet = new EquipmentProductCodeEvent();
				objEPCEventPallet.EquipmentProductCode.FreeFormText.Value = pallet.EpcTagId.FreeFormText.Value;
				objEPCEventPallet.EventType = Convert.ToString(TrackTraceDBManager.Constants.ItemReceivedFromReceiverToReceivingAgent);
				objEPCEventPallet.AssociateEquipmentProductCode = new AssociateEquipmentProductCode[pallet.CaseItemCollection.Count] ;
				objEPCEvent.EquipmentProductCodeEvent[i++] = objEPCEventPallet;
				int j = 0 ;

				objEPCEventPallet.Agent.reportedBy.PartnerDescription.ContactInformation.contactName.FreeFormText.Value =
					"Receiving Agent" ;
				objEPCEventPallet.Agent.reportedBy.PartnerDescription.ContactInformation.facsimileNumber.CommunicationsNumber =
					"425 653 2333" ;
				objEPCEventPallet.Agent.reportedBy.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
					"425 653 2444" ;
				objEPCEventPallet.Agent.reportedBy.PartnerDescription.ContactInformation.EmailAddress =
					"ReceivingAgent@ReceivingAgent.com" ;
				//add the EPC Tag Read type.
				objEPCEventPallet.EPCEventIdentifier = TrackTraceDBManager.Constants.ItemReceivedFromReceiverToReceivingAgent.ToString();
				//Location where it was read.	
				objEPCEventPallet.EventLocation.GlobalLocationIdentifier = "Receiver Location" ;

				foreach(Common.CaseItem caseitem in pallet.CaseItemCollection)
				{
					AssociateEquipmentProductCode objEPCEventCase = new AssociateEquipmentProductCode();
					objEPCEventCase.FreeFormText.Value = caseitem.EpcTagId.FreeFormText.Value;
					objEPCEventPallet.AssociateEquipmentProductCode[j++] = objEPCEventCase;
				}
			}

			proxy.ReceiveEPCEvent ( objEPCEvent ) ;

			lblMessage.Text = "<b>Items successfully received</b> from Receiving agent. Verify all Items are received and <br> send <b>Shipment Receipt Notification</b> to Manufacturer." ;
			btnAcceptGoods.Enabled = false ;
			btnSendOrderCompleteNotification.Enabled = true ;

			ManufacturerWS.BusinessResponse response =	new ManufacturerWS.BusinessResponse () ;
			response.GlobalProcessIndicatorCode =	"4B2" ;
			ManufacturerWS.ReceiptAcknowledgement acknowledgement =	GetAcknowledgement () ;
			response.objAcknowledgement = acknowledgement ;
			
			ManufacturerWS.Pip4B2ShipmentReceiptNotification objPip =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.Pip4B2ShipmentReceiptNotification () ;
			response.objPip = objPip ;

			objPip.fromRole = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.fromRole1 () ;
			objPip.fromRole.PartnerRoleDescription =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PartnerRoleDescription1 () ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation1 () ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.contactName =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName1 () ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText1 () ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang =
				objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value =
				objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.EmailAddress =
				objPipNotification.toRole.PartnerRoleDescription.ContactInformation.EmailAddress ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.facsimileNumber1 () ;
			/* objPip.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber =
				objPipNotification.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber ; */
			objPip.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber1 () ;
			objPip.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
				objPipNotification.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
			objPip.fromRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode =
				objPipNotification.toRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode.ToString () ;
			objPip.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalAddress = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PhysicalAddress1 () ;
			objPip.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalAddress.GlobalLocationIdentifier =
				"Receiver Location" ;

			objPip.thisDocumentGenerationDateTime =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.thisDocumentGenerationDateTime () ;
			objPip.thisDocumentGenerationDateTime.DateTimeStamp =
				DateTime.UtcNow.ToUniversalTime ().ToString ( "yyyyMMddThhmmss.000Z" ); ;
			objPip.thisDocumentIdentifier =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.thisDocumentIdentifier () ;
			objPip.thisDocumentIdentifier.ProprietaryDocumentIdentifier =
				objOrder.OrderNumber ;
			objPip.toRole = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.toRole1 () ;
			objPip.toRole.PartnerRoleDescription =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PartnerRoleDescription1() ;
			objPip.toRole.PartnerRoleDescription.ContactInformation =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation1 () ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.contactName =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName1 () ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText1 () ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang =
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value =
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.EmailAddress =
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.EmailAddress ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.facsimileNumber1 () ;
			/* objPip.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber =
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber ; */
			objPip.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber1 () ;
			objPip.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
			objPip.toRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode =
				objPipNotification.fromRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode.ToString () ;

			objPip.ShipmentReceiptInformationResource =
				new ManufacturerWS.ShipmentReceiptInformationResource[objOrder.PalletItemCollection.Count] ;
			i = 0 ;

			foreach ( Common.PalletItem pallet in
				objOrder.PalletItemCollection )
			{
				objPip.ShipmentReceiptInformationResource[i] = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ShipmentReceiptInformationResource () ;
				objPip.ShipmentReceiptInformationResource[i].shipmentIdentifier =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.shipmentIdentifier () ;
				objPip.ShipmentReceiptInformationResource[i].shipmentIdentifier.ProprietaryReferenceIdentifier =
					pallet.EpcTagId.FreeFormText.Value ;
				objPip.ShipmentReceiptInformationResource[i].ShipmentReceiptNotificationLineItem =
					new ManufacturerWS.ShipmentReceiptNotificationLineItem[pallet.CaseItemCollection.Count] ;

				int j = 0 ;

				foreach ( Common.CaseItem caseObj in
					pallet.CaseItemCollection )
				{
					objPip.ShipmentReceiptInformationResource[i].ShipmentReceiptNotificationLineItem[j] =
						new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ShipmentReceiptNotificationLineItem () ;
					objPip.ShipmentReceiptInformationResource[i].ShipmentReceiptNotificationLineItem[j].ProprietarySerialIdentifier =
						new string[1] ;
					objPip.ShipmentReceiptInformationResource[i].ShipmentReceiptNotificationLineItem[j++].ProprietarySerialIdentifier[0] =
						caseObj.EpcTagId.FreeFormText.Value ;

				} // end nested for

				i ++ ;

			} // end for

			Session["Pip4B2ObjectFromReceiver"] = response ;
			XmlSerializer serializer = new XmlSerializer ( objPip.GetType()) ;
			MemoryStream stream = new MemoryStream () ;
			serializer.Serialize ( stream, objPip ) ;
			string xml = Encoding.ASCII.GetString ( stream.ToArray () ) ;
			txtXml.Text = xml ;
			txtXml.Visible = true ;
			txtXml.Height = 600 ;
			btnAcceptGoods.Visible = false ;
			btnSendOrderCompleteNotification.Visible = true ;
			lnkPrint.Visible = false ;
			lblInformation.Text = "Shipment Receipt Notification" ;
			
		} // end of btnAcceptGoods_Click ()

		/// <summary>
		/// Invoked when the 'Send order complete notification' button is clicked.
		/// </summary>
		/// <param name="sender">The source of the event. </param>
		/// <param name="e">The event-arguments. </param>
		private void btnSendOrderCompleteNotification_Click ( object sender,
			System.EventArgs e )
		{
			ArrayList tagList = GetTagList () ; // get the list of tags
			object[] array = tagList.ToArray () ; // get the EPC-array
			DateTime current = DateTime.Now ; // get the current date-time
			// create a proxy for the web-service
			Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ManufacturerWebService proxy =
				new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ManufacturerWebService () ;
			// check whether security is enabled or not
			string enableSecurity =
				ConfigurationSettings.AppSettings["EnableWSSecurity"] ;

			if ( enableSecurity != null && enableSecurity.ToLower ()
				== "true" ) // if security is enabled
			{
//				X509SecurityToken token = null ;
//				X509CertificateStore store =
//					X509CertificateStore.LocalMachineStore (
//					X509CertificateStore.MyStore ) ; // local machine store
//				// retrieve the token from the store
//				token = RetrieveTokenFromStore ( store, ClientBase64KeyId ) ;
//				/* proxy.RequestSoapContext.Security.Tokens.Add( token );
//					proxy.RequestSoapContext.Security.Elements.Add (
//						new MessageSignature ( token ) ) ; */

			} // end if

			ManufacturerWS.BusinessResponse response =
				( ManufacturerWS.BusinessResponse ) Session["Pip4B2ObjectFromReceiver"] ;
			proxy.ReceiveBusinessAcknowledgement ( response ) ;

			// create a new data-base manager
			TrackTraceDBManager manager = new TrackTraceDBManager (
				TrackTraceDBManager.Constants.Receiver ) ;
			// update the status in the local data-base

			// MS - commented
			// manager.AddEpcStatusInfo ( array,
			//	TrackTraceDBManager.Constants.NotifyOfShipmentReceiptFromReceiverToManufacturer,
			//	current ) ;

			manager.AddFullEpcStatusInfo ( array,
				TrackTraceDBManager.Constants.NotifyOfShipmentReceiptFromReceiverToManufacturer,
				current, objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value,
				objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value,
				"Receiver Location" ) ;

			lblMessage.Text = "<b>Purchase Order processing complete.</b><br>Shipment confirmation receipt successfully sent to Manufacturer.";
			txtXml.Height = 600 ;
			btnAcceptGoods.Visible = false ;
			btnSendOrderCompleteNotification.Visible = false ;
			
		} // end of btnSendOrderCompleteNotification_Click ()

		/// <summary>
		/// Creates order-information.
		/// </summary>
		/// <returns>Order-information object containing </returns>
		private Common.OrderInformation CreateOrderInformationObject ()
		{
			Common.OrderInformation objOrder = new Common.OrderInformation () ;			
			objOrder.OrderNumber = objPipNotification.thisDocumentIdentifier.ProprietaryDocumentIdentifier ;
			objOrder.PalletItemCollection = new PalletItemCollection () ;

			// for each ASN shipping container in the ASN
			foreach ( ASNGenerationService.ShippingContainer container in 
				objPipNotification.AdvancedShipmentNotification.Shipment.ShippingContainer )
			{
				// get the proprietary serial-identifier
				string propriertarySerialIdentifer =
					container.shippingContainerIdentifier.ProprietarySerialIdentifier ;
				int index = propriertarySerialIdentifer.IndexOf ( ' ' ) ;
				string epc = null ;

				// set the EPC from the serial-identifier
				if ( index >= 0 )
					epc = propriertarySerialIdentifer.Substring ( 0,
						index  ) ; // end if

				else
					epc = propriertarySerialIdentifer ; // end else

				PalletItem pallet = new PalletItem () ;
				pallet.EpcTagId.FreeFormText.Value = epc ;
				objOrder.PalletItemCollection.Add ( pallet ) ;

				// for each shipping container-item in the container
				foreach ( ASNGenerationService.ShippingContainerItem item in
					container.ShippingContainerItem )
				{
					// get the proprietary serial-identifier
					propriertarySerialIdentifer =
						item.shippingContainerItemIdentifier.ProprietarySerialIdentifier ;
					index = propriertarySerialIdentifer.IndexOf ( ' ' ) ;
					epc = null ;

					// set the EPC from the serial-identifier
					if ( index >= 0 )
						epc = propriertarySerialIdentifer.Substring ( 0,
							index  ) ; // end if

					else
						epc = propriertarySerialIdentifer ; // end else

					CaseItem caseObj = new CaseItem () ;
					caseObj.EpcTagId.FreeFormText.Value = epc ;
					pallet.CaseItemCollection.Add ( caseObj ) ; // add it to the list

				} // end nested for					

			} // end outer for

			return objOrder ;

		} // end of CreateOrderInformationObject ()

		/// <summary>
		/// Gets an acknowledgement to be sent to the manufacturer.
		/// </summary>
		/// <returns>Acknowledgement to be sent to the manufacturer. </returns>
		private Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ReceiptAcknowledgement
			GetAcknowledgement ()
		{
			// instantiate and populate the receipt-acknowledgement
			Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ReceiptAcknowledgement
				acknowledgement = new
				Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ReceiptAcknowledgement () ;

			if ( objPipNotification != null ) // if the ASN is not null
			{
				acknowledgement.fromRole = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.fromRole () ;
				acknowledgement.fromRole.PartnerRoleDescription =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PartnerRoleDescription () ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation () ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.contactName =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName () ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.EmailAddress =
					objPipNotification.toRole.PartnerRoleDescription.ContactInformation.EmailAddress ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.facsimileNumber () ;
				/* acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber =
					objPipNotification.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber ; */
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber () ;
				acknowledgement.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
					objPipNotification.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
				acknowledgement.fromRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode =
					objPipNotification.toRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode.ToString () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.BusinessDescription () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.businessName () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.Value ; */
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.lang ; */
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.lang ; */
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.Value ; */
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.EmailAddress =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.EmailAddress ; */
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber () ;
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber ; */
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PhysicalLocation () ;
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.GlobalLocationIdentifier =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.GlobalLocationIdentifier ; */
				/* acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PhysicalAddress () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine1 () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine2 () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine3 () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.cityName () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.GlobalCountryCode =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.GlobalCountryCode ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.postOfficeBoxIdentifier () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.lang =
                    objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.Value=
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.Value ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.regionName () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.lang =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.lang ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.Value =
					objPipNotification.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.Value ;

				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.BusinessDescription () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.businessName () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.BusinessDescription.businessName.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.contactName.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.EmailAddress =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.EmailAddress ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber () ;
				acknowledgement.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PhysicalLocation () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.GlobalLocationIdentifier =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.GlobalLocationIdentifier ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PhysicalAddress () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine1 () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine1.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine2 () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine2.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3 = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.addressLine3 () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.addressLine3.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.cityName () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.cityName.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.GlobalCountryCode =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.GlobalCountryCode ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.NationalPostalCode ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.postOfficeBoxIdentifier () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.Value=
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.postOfficeBoxIdentifier.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.regionName () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText = new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.PartnerDescription.PhysicalLocation.PhysicalAddress.regionName.FreeFormText.Value ; */

				acknowledgement.receivedDocumentDateTime =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.receivedDocumentDateTime () ;
				acknowledgement.receivedDocumentDateTime.DateTimeStamp =
					DateTime.UtcNow.ToUniversalTime ().ToString ( "yyyyMMddThhmmss.000Z" ); ;
				acknowledgement.receivedDocumentIdentifier =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.receivedDocumentIdentifier () ;
				acknowledgement.receivedDocumentIdentifier.ProprietaryDocumentIdentifier =
					objPipNotification.thisDocumentIdentifier.ProprietaryDocumentIdentifier ;
				acknowledgement.thisMessageDateTime =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.thisMessageDateTime () ;
				acknowledgement.thisMessageDateTime.DateTimeStamp =
					DateTime.UtcNow.ToUniversalTime ().ToString ( "yyyyMMddThhmmss.000Z" ); ;
				acknowledgement.thisMessageIdentifier =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.thisMessageIdentifier () ;
				acknowledgement.thisMessageIdentifier.ProprietaryMessageIdentifier =
					"Shipment receipt-notice. " ;
				acknowledgement.toRole =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.toRole () ;
				acknowledgement.toRole.PartnerRoleDescription =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.PartnerRoleDescription () ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.ContactInformation () ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.contactName =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.contactName () ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.FreeFormText () ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang =
					objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.lang ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value =
					objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.contactName.FreeFormText.Value ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.EmailAddress =
					objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.EmailAddress ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.facsimileNumber () ;
				/* acknowledgement.toRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber =
					objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.facsimileNumber.CommunicationsNumber ; */
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber =
					new Microsoft.RFIDLab.EPCISDemo.ManufacturerWS.telephoneNumber () ;
				acknowledgement.toRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber =
					objPipNotification.fromRole.PartnerRoleDescription.ContactInformation.telephoneNumber.CommunicationsNumber ;
				acknowledgement.toRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode =
					objPipNotification.fromRole.PartnerRoleDescription.GlobalPartnerRoleClassificationCode.ToString () ;

			} // end if

			return acknowledgement ;

		} // end of GetAcknowledgement ()

		/// <summary>
		/// Gets a list of all EPC tags in the session.
		/// </summary>
		/// <returns>Array-list containing all pallet and case EPCs. </returns>
		private ArrayList GetTagList ()
		{
			ArrayList result = new ArrayList () ;

			if ( objPipNotification != null ) // if the ASN is not null
			{
				// for each ASN shipping container in the ASN
				foreach ( ASNGenerationService.ShippingContainer container in 
					objPipNotification.AdvancedShipmentNotification.Shipment.ShippingContainer )
				{
					// for each shipping container-item in the container
					// get the proprietary serial-identifier
					string propriertarySerialIdentifer =
						container.shippingContainerIdentifier.ProprietarySerialIdentifier ;
					int index = propriertarySerialIdentifer.IndexOf ( ' ' ) ;
					string epc = null ;

					// set the EPC from the serial-identifier
					if ( index >= 0 )
						epc = propriertarySerialIdentifer.Substring ( 0,
							index  ) ; // end if 

					else
						epc = propriertarySerialIdentifer ; // end else

					result.Add ( epc ) ; // add it to the list

					foreach ( ASNGenerationService.ShippingContainerItem item in
						container.ShippingContainerItem )
					{
						// get the proprietary serial-identifier
						propriertarySerialIdentifer =
							item.shippingContainerItemIdentifier.ProprietarySerialIdentifier ;
						index = propriertarySerialIdentifer.IndexOf ( ' ' ) ;
						epc = null ;

						// set the EPC from the serial-identifier
						if ( index >= 0 )
							epc = propriertarySerialIdentifer.Substring ( 0,
								index  ) ; // end if 

						else
							epc = propriertarySerialIdentifer ; // end else

						result.Add ( epc ) ; // add it to the list

					} // end nested for

				} // end outer for

			} // end if

			return result ; // return the result

		} // end of GetTagList ()

//		/// <summary>
//		/// Gets a security-token.
//		/// </summary>
//		/// <param name="store">The store. </param>
//		/// <param name="keyIdentifier">The key to identify. </param>
//		/// <returns>Instance of the security-token. </returns>
//		private static X509SecurityToken RetrieveTokenFromStore (
//			X509CertificateStore store, string keyIdentifier )
//		{
//			// if the store specified is null, throw an exception 
//			if ( store == null )
//				throw new ArgumentNullException ( "store" ) ; // end if
//            
//			X509SecurityToken token = null ;
//
//			try 
//			{
//				if ( store.OpenRead () ) // if the store gets opened for reading
//				{
//					/* Place the key-ID of the certificate in a byte-array.
//					 * This key-ID represents the Wse2Quickstart certificate
//					 * included with the WSE 2.0 Quickstarts.
//					 * ClientBase64KeyId is defined in the ClientBase.AppBase
//					 * class */
//					X509CertificateCollection certs =
//						store.FindCertificateByKeyIdentifier (
//						Convert.FromBase64String ( keyIdentifier ) ) ;
//
//					// if a certificate is found, get the first
//					if ( certs.Count > 0 )						
//						token = new X509SecurityToken ( (
//							( X509Certificate ) certs[0] ) ) ; // end if
//
//					else // no certificates found - throw an exception
//						throw new ApplicationException (
//							"X509-certificate not found in local store." ) ;
//					// end else
//
//				} // end if
//
//			} // end of try block
//
//			finally
//			{
//				if ( store != null ) // if the store is not null, close it
//					store.Close () ; // end if
//
//			} // end of finally block
//  
//			return token ; // return the token
//
//		} // end of RetrieveTokenFromStore ()
//
	} // class definition over

} // end of namespace
