Sample Codes — Java

Note that “limit” attribute is always required, but for the sake of saving space, only the first example shows the loop which correctly gets multiple batches of data.

Read with equal to Method — Java

            // Create a read request for an envelope with internal ID 211
ReadRequest[] reads = new ReadRequest[1];
reads[0] = new ReadRequest();
reads[0].setType("Envelope"); // we are requesting Envelope type
reads[0].setMethod("equal to"); // method to return a specific
envelope
oaEnvelope env = new oaEnvelope();
env.setId("211");
reads[0].setObjects(new oaBase[]{env});
int limit = 1000; // only read 1000 records at a time
int index = 0;// record index to start the read from
// add an attribute to our read, specifying the base record # (index)
// and the max # of records to be returned (limit)
Attribute attr = new Attribute();
attr.setName("limit");
attr.setValue(String.format("%1$d", limit));
reads[0].setAttributes(new Attribute[]{attr}); // perform the read
System.out.print("Fetching envelopes...");
ReadResult[] results = binding.read(reads); // output the results
while(true) {
   int numRead = 0;
   for (int i = 0; i < results.length; ++i) {
      ReadResult r = results[i];
      if (r.getObjects() != null) { 
         System.out.println("Read " + r.getObjects().length + " envelopes\n");
         oaBase[] objs = r.getObjects();
         for (numRead = 0; numRead < objs.length; ++numRead) {
            oaEnvelope envelope = (oaEnvelope)objs[numRead];
            System.out.println("Envelope name: " + envelope.getName());
            System.out.println("Envelope number: " + envelope.getNumber());
            System.out.println("Envelope total: " + envelope.getTotal());
            System.out.println();
            // ..etc.
            index++;
         }
         System.out.println("Read "+numRead+" envelopes");
      } else {
      System.out.println("Read 0 envelopes\n");
      }
   } 
   // if we've read up to the limit, do another read using index as our base 
   if( numRead == limit ) {
      System.out.println("Fetching "+ limit +" more envelopes");
      attr.setValue(String.format("%1$d, %2$d", index, limit));
      results = binding.read(reads); 
   } else {
      // no more to read 
      break;
   }
} 

          

Read with not equal to Method — Java

Note that the “limit” attribute is required as illustrated in Read with equal to Method — Java.

            // Create a read request for envelopes with a non-zero total.
ReadRequest[] reads = new ReadRequest[1];
reads[0] = new ReadRequest();
reads[0].setType("Envelope"); // we are requesting Envelope type
reads[0].setMethod("not equal to"); // method to return a subset of
data based on search criteria. // We are searching for an envelope with total not equal to 0.
oaEnvelope obj = new oaEnvelope();
obj.setTotal("0.00");
reads[0].setObjects(new oaEnvelope[] { obj }); // perform the read
System.out.print("Fetching envelopes...");
ReadResult[] results = binding.read(reads); // output the results
for (int i = 0; i < results.length; ++i)
{ ReadResult r = results[i]; if (r.getObjects() != null) { System.out.println("Read " + r.getObjects().length + " envelopes\n"); oaBase[] objs = r.getObjects(); for (int j = 0; j < objs.length; ++j) { oaEnvelope env = (oaEnvelope)objs[j]; System.out.println("Envelope name: " + nv.getName()); System.out.println("Envelope number: " + env.getNumber()); System.out.println("Envelope total: " + nv.getTotal()); System.out.println(); // ..etc. } } else { System.out.println("Read 0 envelopes\n"); }
} 

          

Read Not Exported Charges with all Method — Java

Note that the “limit” attribute is required as illustrated in Read with equal to Method — Java.

            // Read all slips, but add a filter so we only retrieve not-yet-exported
records.
// Below is an example on how to mark items as being exported.
Attribute attr = new Attribute();
attr.setName( "filter" );
attr.setValue( "not-exported" );
ReadRequest read = new ReadRequest();
read.setMethod( "all" );
read.setType( "Slip" );
read.setAttributes( new Attribute[]{attr} );

// Tell the server we're filtering on import_export records created by
MY_APP
oaImportExport importExport = new oaImportExport();
importExport.setApplication( "MY_APP" );
read.setObjects( new oaBase[] { importExport } );

ReadResult[] results = binding.read(new ReadRequest[] { read });

// To modify and read not-yet exported slips
// Mark the slip with ID = 4 as exported by the application
// MY_APP on 4/1/2011. By doing this, we can add a filter attribute to
// our read call that will filter out records exported by MY_APP.
oaImportExport exportRecord = new oaImportExport();
exportRecord.setApplication( "MY_APP" );
exportRecord.setType( "Slip" );
exportRecord.setId( "4" );
exportRecord.setExported( "2011-04-01 00:00:00" );
UpdateResult[] ur = binding.upsert( new Attribute[]{}, new oaBase[] {

exportRecord }); 

          

Read with all Method and Date Filters — Java

Note that the “limit” attribute is required as illustrated in Read with equal to Method — Java.

            // Request envelope records updated based on a certain date.
ReadRequest read = new ReadRequest();
Attribute attr = new Attribute();
attr.setName( "filter" );
attr.setValue( "newer-than,older-than" ); // filter for records in
date range separated by a comma
Attribute field = new Attribute();
field.setName( "field" );
field.setValue( = "updated,updated" ); //one for each date object
separated by a comma
read.setMethod( "all" );
read.setType( "Envelope" );
read.setAttributes( new Attribute[]{attr});

oaDate dateNewer = new oaDate();
oaDate dateOlder = new oaDate();

// set newer than date.
dateNewer.setYear( "2008" );
dateNewer.setMonth( "10" );
dateNewer.setDay( "16" );

// set older than date.
dateOlder.setYear( "2008" );
dateOlder.setMonth( "10" );
dateOlder.setDay( "17" );

read.setObjects(new oaBase[] { dateNewer,dateOlder });
ReadResult[] results = stub.read(new ReadRequest[] { read });