Java: Get Letter Metadata with GetLetterDetailsV2()
Download our Java samples from this page. Find this sample in directory /test/com/postalmethods/client
package com.postalmethods.client; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.postalmethods.client.api.GetLetterDetailsV2Response; import com.postalmethods.client.api.SendLetterV2Response; public class GetLetterDetailsV2Test { private PostalMethodsClient client; private int letterId; @Before public void setUp() { client = new PostalMethodsClientFactory().build(); // Send a sample letter so we have a letterId to check status on. SendLetterV2Response sendResponse = client.sendLetterV2("Junit test letter 1", TestConstants.SAMPLE_LETTER_FILENAME); int code = sendResponse.getResult().getCode(); assertTrue(code > 0 ); this.letterId = code; } @Test public void testGetLetterDetails() { System.out.println("Making call to GetLetterDetailsV2..."); GetLetterDetailsV2Response response = client.getLetterDetailsV2(letterId); System.out.println("Service call completed:\n" + response.getResult().toString()); int code = response.getResult().getCode(); assertEquals( -3000, code ); // success System.out.println(response.getLetterDetails().toString()); } }
