diff --git a/commerce_shipping_matrix.binpacking.inc b/commerce_shipping_matrix.binpacking.inc
new file mode 100644
index 0000000..5d10768
--- /dev/null
+++ b/commerce_shipping_matrix.binpacking.inc
@@ -0,0 +1,408 @@
+<?php
+/**
+ * @file
+ * Box packing algorithm for the Shipping Matrix Module
+ */
+
+
+
+/**
+ *
+ * credits:  https://github.com/yetzt/boxing
+ *
+ * this some kind of box packing algorithm,
+ * check if n boxes fit in n bigger boxes
+ * i use this for checking if items will fit a packaging box
+ * if this algorithm says true: they do definitely fit
+ * if this algorithm says false: they most probably will not fit, but this is a program, not a cop.
+ * 
+ * disclaimer: 
+ * 
+ * this is not an accurate solution for knapsack or any of those fancy np-complete combinatory problems
+ * i am not a mathematican, i have no idea what i am talking about, and also the german wikipedia sucks on this topic
+ * quick and dirty, works for me, public domain, donations very welcome
+ * 
+ * author: sebastian vollnhals <sebastian at vollnhals dot info>
+ * 
+ * usage:
+ * 
+ * $b = new boxing();
+ * 
+ * $b -> add_outer_box(40,30,30); // our quantum box; l, w, h
+ * 
+ * $b -> add_inner_box(20,30,40); // schroedingers cat; l, w, h
+ * $b -> add_inner_box(10,5,5); // the poison; l, w, h
+ * $b -> add_inner_box(5,5,10); // some katzenstreu; l, w, h
+ *
+ * if ($b -> fits()) {
+ *
+ *  // schroedingers cat and schroedingers stuff do fit in the box
+ *
+ * }
+ *
+ */
+
+class boxing {
+
+  private $outer_boxes;
+  private $inner_boxes;
+
+  public function boxing() {
+
+    $this -> outer_boxes = array();
+    $this -> inner_boxes = array();
+
+    return;
+
+  }
+
+  public function add_outer_box($l, $w, $h) {
+
+    if ($l > 0 && $w > 0 && $h > 0) {
+
+      $this -> outer_boxes[] = array(
+
+        "dimensions" => $this -> sort_dimensions($l, $w, $h),
+        "packed" => FALSE
+
+      );
+
+    }
+
+    return TRUE;
+
+  }
+
+  public function add_inner_box($l, $w, $h) {
+
+    if ($l > 0 && $w > 0 && $h > 0) {
+
+      $this -> inner_boxes[] = array(
+
+        "dimensions" => $this -> sort_dimensions($l, $w, $h),
+        "packed" => FALSE
+
+      );
+
+    }
+
+    return TRUE;
+
+  }
+
+
+  public function fits() {
+
+    /* first we do a simple volume check, this can save a lot of calculations */
+
+    if (!$this -> fits_volume()) {
+
+      return FALSE;
+
+    }
+
+    /* get next inner box */
+
+    while (TRUE) {
+
+      $inner_box_id = $this->next_inner_box();
+
+      if ($inner_box_id === FALSE) {
+
+        break;
+
+      }
+
+      $this -> sort_outer_boxes(); // smallest first
+
+      $found_fitting_box = FALSE;
+
+      foreach ($this->outer_boxes as $outer_box_id => $outer_box) {
+
+        if (!$outer_box["packed"] && $this->fits_inside($inner_box_id, $outer_box_id)) {
+
+          /* matches! */
+
+          $this -> inner_boxes[$inner_box_id]["packed"] = TRUE;
+          $this -> outer_boxes[$outer_box_id]["packed"] = TRUE;
+
+          $this -> find_subboxes($inner_box_id, $outer_box_id);
+
+          $found_fitting_box = TRUE;
+
+          break;
+
+        }
+
+      }
+
+      if (!$found_fitting_box) {
+
+        return FALSE;
+
+      }
+
+    }
+
+    /* we ran out of inner boxes but have outer boxes left */
+
+    return TRUE;
+
+  }
+
+  public function fits_volume() {
+
+    $inner_volume = 0;
+    $outer_volume = 0;
+
+    foreach ($this -> inner_boxes as $inner) {
+
+      $inner_volume += ($inner["dimensions"][0] * $inner["dimensions"][1] * $inner["dimensions"][2]);
+
+    }
+
+    foreach ($this -> outer_boxes as $outer) {
+
+      $outer_volume += ($outer["dimensions"][0] * $outer["dimensions"][1] * $outer["dimensions"][2]);
+
+    }
+
+    if ($inner_volume > $outer_volume) {
+
+      /* inner boxes have more volume than outer ones */
+
+      return FALSE;
+
+    } 
+    else {
+
+      return TRUE;
+
+    }
+
+  }
+
+  private function find_subboxes($inner_box_id, $outer_box_id) {
+
+    $inner_dimensions = $this->inner_boxes[$inner_box_id]["dimensions"];
+    $outer_dimensions = $this->outer_boxes[$outer_box_id]["dimensions"];
+
+    sort($outer_dimensions);
+
+    $pairs = array();
+
+    foreach ($inner_dimensions as $inner_id => $inner_value) {
+
+      foreach ($outer_dimensions as $outer_id => $outer_value) {
+
+        if ($inner_value <= $outer_value) {
+
+          $unset = $outer_id;
+
+          $pairs[] = array(
+
+            "inner" => $inner_value,
+            "outer" => $outer_value,
+            "diff" => $outer_value-$inner_value
+
+          );
+
+          break;
+
+        }
+
+      }
+
+      unset($outer_dimensions[$unset]);
+
+    }
+
+    do {
+
+      $pairs = $this-> _diffsort($pairs);
+
+      $this -> add_outer_box($pairs[0]["diff"], $pairs[1]["outer"], $pairs[2]["outer"]);
+
+      $pairs[0]["diff"] = 0;
+      $pairs[0]["outer"] = $pairs[0]["inner"];
+
+
+    } while ($pairs[0]["diff"] > 0 || $pairs[1]["diff"] > 0 || $pairs[2]["diff"] > 0);
+
+    return TRUE;
+
+  }
+
+  private function fits_inside($inner_box_id, $outer_box_id) {
+
+    if (
+
+      $this->inner_boxes[$inner_box_id]["dimensions"][0] <= $this->outer_boxes[$outer_box_id]["dimensions"][0] &&
+      $this->inner_boxes[$inner_box_id]["dimensions"][1] <= $this->outer_boxes[$outer_box_id]["dimensions"][1] &&
+      $this->inner_boxes[$inner_box_id]["dimensions"][2] <= $this->outer_boxes[$outer_box_id]["dimensions"][2]
+
+    ) {
+
+      /* fits */
+
+      return TRUE;
+
+    }
+    else {
+
+      /* fits not */
+
+      return FALSE;
+
+    }
+
+  }
+
+  private function sort_dimensions($l, $w, $h) {
+
+    $dimensions = array($l, $w, $h);
+
+    rsort($dimensions);
+
+    return $dimensions;
+
+  }
+
+  private function sort_outer_boxes() {
+
+    foreach ($this -> outer_boxes as $k => $v) {
+
+      $this -> outer_boxes[$k]["longest_side"] = $v["dimensions"][0];
+
+    }
+
+    $this -> outer_boxes = $this -> _sksort($this -> outer_boxes, "longest_side", FALSE, TRUE);
+
+    return TRUE;
+
+  }
+
+  private function next_outer_box() {
+
+    $biggest_size = 0;
+    $biggest_id = FALSE;
+
+    foreach ($this -> outer_boxes as $id => $box) {
+
+      if (!$box["packed"] && $box["dimensions"][0] > $biggest_size) {
+
+        $biggest_size = $box["dimensions"][0];
+        $biggest_id = $id;
+
+      }
+
+    }
+
+    return $id;
+
+  }
+
+  private function next_inner_box() {
+
+    $biggest_size = 0;
+    $biggest_id = FALSE;
+
+    foreach ($this -> inner_boxes as $id => $box) {
+
+      if (!$box["packed"] && $box["dimensions"][0] > $biggest_size) {
+
+        $biggest_size = $box["dimensions"][0];
+        $biggest_id = $id;
+
+      }
+
+    }
+
+    return $biggest_id;
+
+  }
+
+  private function _sksort($array, $subkey, $sort_descending=FALSE, $keep_keys_in_sub=FALSE) {
+
+    // slightly modified since stolen from http://www.php.net/manual/de/function.sort.php#93473
+
+    foreach ($array as $key => &$value) {
+
+      $sort = array();
+
+      foreach ($value as $index => $val) {
+
+        $sort[$index] = $val[$subkey];
+
+      }
+
+      asort($sort);
+
+      $keys = array_keys($sort);
+
+      $new_value = array();
+
+      foreach ($keys as $index) {
+
+        if ($keep_keys_in_sub) {
+
+          $new_value[$index] = $value[$index];
+
+        } 
+        else {
+
+          $new_value[] = $value[$index];
+
+        }
+
+      }
+
+      if ($sort_descending) {
+
+        $value = array_reverse($new_value, $keep_keys_in_sub);
+
+      } 
+      else {
+
+        $value = $new_value;
+
+      }
+
+    }
+
+    return $array;
+
+  }
+
+  function _diffsort($array) {
+
+    /* quick and dirty hack since _sksort() does strange things */
+
+    $tmp_array = array();
+
+    foreach ($array as $item) {
+
+      $tmp_array[(string)$item["diff"]][] = $item;
+
+    }
+
+    krsort($tmp_array, SORT_NUMERIC);
+
+    $array = array();
+
+    foreach ($tmp_array as $a) {
+
+      foreach ($a as $item) {
+
+        $array[] = $item;
+
+      }
+
+    }
+
+    return $array;
+
+  }
+
+}
+
diff --git a/commerce_shipping_matrix.controllers.inc b/commerce_shipping_matrix.controllers.inc
new file mode 100644
index 0000000..f558e51
--- /dev/null
+++ b/commerce_shipping_matrix.controllers.inc
@@ -0,0 +1,391 @@
+<?php
+
+/**
+ * @file
+ * Enitity Controlers for the Shipping Matrix Module
+ */
+
+
+/**
+ * ShippingMatrixShippingServiceControllerInterface definition.
+ *
+ * We create an interface here because anyone could come along and
+ * use hook_entity_info_alter() to change our controller class.
+ * We want to let them know what methods our class needs in order
+ * to function with the rest of the module, so here's a handy list.
+ *
+ * see hook_entity_info_alter()
+ */
+
+interface ShippingMatrixShippingServiceControllerInterface
+  extends DrupalEntityControllerInterface {
+  public function create();
+  public function save($entity);
+  public function delete($entity);
+}
+
+/**
+ * EntityExampleBasicController extends DrupalDefaultEntityController.
+ *
+ * Our subclass of DrupalDefaultEntityController lets us add a few
+ * important create, update, and delete methods.
+ */
+class ShippingMatrixShippingServiceController
+  extends DrupalDefaultEntityController
+  implements ShippingMatrixShippingServiceControllerInterface {
+
+  /**
+   * Create and return a new entity_example_basic entity.
+   */
+  public function create() {
+    $entity = new stdClass();
+    $entity->type = 'shipping_matrix_services';
+    $entity->bundle_type = 'shipping_matrix_services';
+    $entity->is_new = TRUE;
+    //$entity->shipping_service_id = false;
+    $entity->item_description = '';
+    return $entity;
+  }
+
+  /**
+   * Saves the custom fields using drupal_write_record()
+   */
+  public function save($entity) {
+    // If our entity has no basic_id, then we need to give it a
+    // time of creation.
+    // Invoke hook_entity_presave().
+    module_invoke_all('entity_presave', $entity, 'shipping_matrix_services');
+
+    // The 'primary_keys' argument determines whether this will be an insert
+    // or an update. So if the entity already has an ID, we'll specify
+    // basic_id as the key.
+    $primary_keys = array();
+    if (isset($entity->shipping_service_id)) { 
+      $primary_keys = $entity->shipping_service_id ? 'shipping_service_id' : array();
+    }
+  
+    // Write out the entity record.
+    // table to write to, entity data to write to table, primairy key
+    drupal_write_record('shipping_matrix_shipping_service', $entity, $primary_keys);
+
+    // We're going to invoke either hook_entity_update() or
+    // hook_entity_insert(), depending on whether or not this is a
+    // new entity. We'll just store the name of hook_entity_insert()
+    // and change it if we need to.
+    $invocation = 'entity_insert';
+    // Now we need to either insert or update the fields which are
+    // attached to this entity. We use the same primary_keys logic
+    // to determine whether to update or insert, and which hook we
+    // need to invoke.
+  
+
+    if (empty($primary_keys)) {
+      field_attach_insert('shipping_matrix_services', $entity);
+    }
+    else {
+      field_attach_update('shipping_matrix_services', $entity);
+      $invocation = 'entity_update';
+    }
+    // Invoke either hook_entity_update() or hook_entity_insert().
+    module_invoke_all($invocation, $entity, 'shipping_matrix_services');
+
+    return $entity;
+  }
+
+  /**
+   * Delete a single entity.
+   *
+   * Really a convenience function for delete_multiple().
+   */
+  public function delete($entity) {
+    $this->delete_multiple(array($entity));
+  }
+
+  /**
+   * Delete one or more entity_example_basic entities.
+   *
+   * Deletion is unfortunately not supported in the base
+   * DrupalDefaultEntityController class.
+   *
+   * @param $basic_ids
+   *   An array of entity IDs or a single numeric ID.
+   */
+  public function delete_multiple($entities) {
+    $shipping_service_id = array();
+    if (!empty($entities)) {
+      $transaction = db_transaction();
+      try {
+        foreach ($entities as $entity) {
+          module_invoke_all('shipping_matrix_services_delete', $entity);
+          // Invoke hook_entity_delete().
+          module_invoke_all('entity_delete', $entity, 'shipping_matrix_shippingservice');
+          field_attach_delete('shipping_matrix_services', $entity);
+          $shipping_service_id[] = $entity->shipping_service_id;
+        }
+        db_delete('shipping_matrix_shipping_service')
+          ->condition('shipping_service_id', $shipping_service_id, 'IN')
+          ->execute();
+
+      }
+      catch (Exception $e) {
+        $transaction->rollback();
+        watchdog_exception('shipping_matrix', $e);
+        throw $e;
+      }
+    }
+  }
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+/**
+ * ShippingMatrixZonesControllerInterface definition.
+ *
+ * We create an interface here because anyone could come along and
+ * use hook_entity_info_alter() to change our controller class.
+ * We want to let them know what methods our class needs in order
+ * to function with the rest of the module, so here's a handy list.
+ *
+ * see hook_entity_info_alter()
+ */
+
+interface ShippingMatrixZonesControllerInterface
+  extends DrupalEntityControllerInterface {
+  public function create();
+  public function save($entity);
+  public function delete($entity);
+}
+
+/**
+ * EntityExampleBasicController extends DrupalDefaultEntityController.
+ *
+ * Our subclass of DrupalDefaultEntityController lets us add a few
+ * important create, update, and delete methods.
+ */
+class ShippingMatrixZonesController
+  extends DrupalDefaultEntityController
+  implements ShippingMatrixZonesControllerInterface {
+
+  /**
+   * Create and return a new entity_example_basic entity.
+   */
+  public function create() {
+    $entity = new stdClass();
+    $entity->type = 'shipping_matrix_zone';
+    $entity->shipping_zone_id = 0;
+    $entity->bundle_type = 'shipping_matrix_zone';
+    $entity->item_description = '';
+    return $entity;
+  }
+
+  /**
+   * Saves the custom fields using drupal_write_record()
+   */
+  public function save($entity) {
+    // If our entity has no basic_id, then we need to give it a
+    // time of creation.
+    if (empty($entity->shipping_zone_id)) {
+      $entity->created = time();
+    }
+    // Invoke hook_entity_presave().
+    module_invoke_all('entity_presave', $entity, 'shipping_matrix_zone');
+    // The 'primary_keys' argument determines whether this will be an insert
+    // or an update. So if the entity already has an ID, we'll specify
+    // basic_id as the key.
+    $primary_keys = $entity->shipping_zone_id ? 'shipping_zone_id' : array();
+    // Write out the entity record.
+    drupal_write_record('shipping_matrix_shipping_zone', $entity, $primary_keys);
+    // We're going to invoke either hook_entity_update() or
+    // hook_entity_insert(), depending on whether or not this is a
+    // new entity. We'll just store the name of hook_entity_insert()
+    // and change it if we need to.
+    $invocation = 'entity_insert';
+    // Now we need to either insert or update the fields which are
+    // attached to this entity. We use the same primary_keys logic
+    // to determine whether to update or insert, and which hook we
+    // need to invoke.
+    if (empty($primary_keys)) {
+      field_attach_insert('shipping_matrix_zone', $entity);
+    }
+    else {
+      field_attach_update('shipping_matrix_zone', $entity);
+      $invocation = 'entity_update';
+    }
+    // Invoke either hook_entity_update() or hook_entity_insert().
+    module_invoke_all($invocation, $entity, 'shipping_matrix_zone');
+    return $entity;
+  }
+
+  /**
+   * Delete a single entity.
+   *
+   * Really a convenience function for delete_multiple().
+   */
+  public function delete($entity) {
+    $this->delete_multiple(array($entity));
+  }
+
+  /**
+   * Delete one or more entity_example_basic entities.
+   *
+   * Deletion is unfortunately not supported in the base
+   * DrupalDefaultEntityController class.
+   *
+   * @param $basic_ids
+   *   An array of entity IDs or a single numeric ID.
+   */
+  public function delete_multiple($entities) {
+    $shipping_zone_id = array();
+    if (!empty($entities)) {
+      $transaction = db_transaction();
+      try {
+        foreach ($entities as $entity) {
+          module_invoke_all('shipping_matrix_zone_delete', $entity);
+          // Invoke hook_entity_delete().
+          module_invoke_all('entity_delete', $entity, 'shipping_matrix_zone');
+          field_attach_delete('shipping_matrix_zone', $entity);
+          $shipping_zone_id[] = $entity->shipping_zone_id;
+        }
+        db_delete('shipping_matrix_shipping_zone')
+          ->condition('shipping_zone_id', $shipping_zone_id, 'IN')
+          ->execute();
+
+      }
+      catch (Exception $e) {
+        $transaction->rollback();
+        watchdog_exception('shipping_matrix', $e);
+        throw $e;
+      }
+    }
+  }
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+
+
+/**
+ * ShippingMatrixTableWeightControllerInterface definition.
+ *
+ * We create an interface here because anyone could come along and
+ * use hook_entity_info_alter() to change our controller class.
+ * We want to let them know what methods our class needs in order
+ * to function with the rest of the module, so here's a handy list.
+ *
+ * see hook_entity_info_alter()
+ */
+
+interface ShippingMatrixTableWeightControllerInterface
+  extends DrupalEntityControllerInterface {
+  public function create();
+  public function save($entity);
+  public function delete($entity);
+}
+
+/**
+ * EntityExampleBasicController extends DrupalDefaultEntityController.
+ *
+ * Our subclass of DrupalDefaultEntityController lets us add a few
+ * important create, update, and delete methods.
+ */
+class ShippingMatrixTableWeightController
+  extends DrupalDefaultEntityController
+  implements ShippingMatrixTableWeightControllerInterface {
+
+  /**
+   * Create and return a new entity_example_basic entity.
+   */
+  public function create() {
+    $entity = new stdClass();
+    $entity->type = 'shipping_matrix_weight_table';
+    $entity->weight_table_id = 0;
+    $entity->bundle_type = 'shipping_matrix_weight_table';
+    $entity->item_description = '';
+    return $entity;
+  }
+
+  /**
+   * Saves the custom fields using drupal_write_record()
+   */
+  public function save($entity) {
+    // If our entity has no basic_id, then we need to give it a
+    // time of creation.
+    // Invoke hook_entity_presave().
+    module_invoke_all('entity_presave', $entity, 'shipping_matrix_weight_table');
+    // The 'primary_keys' argument determines whether this will be an insert
+    // or an update. So if the entity already has an ID, we'll specify
+    // basic_id as the key.
+    $primary_keys = $entity->weight_table_id ? 'weight_table_id' : array();
+    // Write out the entity record.
+    drupal_write_record('shipping_matrix_weight_table', $entity, $primary_keys);
+    // We're going to invoke either hook_entity_update() or
+    // hook_entity_insert(), depending on whether or not this is a
+    // new entity. We'll just store the name of hook_entity_insert()
+    // and change it if we need to.
+    $invocation = 'entity_insert';
+    // Now we need to either insert or update the fields which are
+    // attached to this entity. We use the same primary_keys logic
+    // to determine whether to update or insert, and which hook we
+    // need to invoke.
+    if (empty($primary_keys)) {
+      field_attach_insert('shipping_matrix_weight_table', $entity);
+    }
+    else {
+      field_attach_update('shipping_matrix_weight_table', $entity);
+      $invocation = 'entity_update';
+    }
+    // Invoke either hook_entity_update() or hook_entity_insert().
+    module_invoke_all($invocation, $entity, 'shipping_matrix_weight_table');
+    return $entity;
+  }
+
+  /**
+   * Delete a single entity.
+   *
+   * Really a convenience function for delete_multiple().
+   */
+  public function delete($entity) {
+    $this->delete_multiple(array($entity));
+  }
+
+  /**
+   * Delete one or more entity_example_basic entities.
+   *
+   * Deletion is unfortunately not supported in the base
+   * DrupalDefaultEntityController class.
+   *
+   * @param $basic_ids
+   *   An array of entity IDs or a single numeric ID.
+   */
+  public function delete_multiple($entities) {
+    $weight_table_id = array();
+    if (!empty($entities)) {
+      $transaction = db_transaction();
+      try {
+        foreach ($entities as $entity) {
+          module_invoke_all('shipping_matrix_weight_table_delete', $entity);
+          // Invoke hook_entity_delete().
+          module_invoke_all('entity_delete', $entity, 'shipping_matrix_weight_table');
+          field_attach_delete('shipping_matrix_weight_table', $entity);
+          $weight_table_id[] = $entity->weight_table_id;
+        }
+        db_delete('shipping_matrix_weight_table')
+          ->condition('weight_table_id', $weight_table_id, 'IN')
+          ->execute();
+
+      }
+      catch (Exception $e) {
+        $transaction->rollback();
+        watchdog_exception('shipping_matrix', $e);
+        throw $e;
+      }
+    }
+  }
+}
+
+
+//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
+
diff --git a/commerce_shipping_matrix.info b/commerce_shipping_matrix.info
new file mode 100644
index 0000000..d5af656
--- /dev/null
+++ b/commerce_shipping_matrix.info
@@ -0,0 +1,12 @@
+name = Commerce Shipping Matrix
+description = Provides a weight and country based shipping method.
+package = Commerce (shipping)
+dependencies[] = commerce
+dependencies[] = physical
+dependencies[] = commerce_physical
+dependencies[] = commerce_shipping
+dependencies[] = entity
+
+core = 7.x
+
+
diff --git a/commerce_shipping_matrix.install b/commerce_shipping_matrix.install
new file mode 100644
index 0000000..84217b7
--- /dev/null
+++ b/commerce_shipping_matrix.install
@@ -0,0 +1,483 @@
+<?php
+
+/**
+ * @file
+ * Handles installation for Shipping Matrix module.
+ */
+
+/**
+ * Implements hook_schema().
+ *
+ */
+
+function commerce_shipping_matrix_schema() { 
+  
+  $schema['shipping_matrix_shipping_service'] = array(
+    'description' => 'This table holds the shipping services',
+    'fields' => array(
+      'shipping_service_id' => array(
+        'description' => 'the unique identifier for the shipping service',
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'shipping_service_name' => array(
+        'description' => 'The name of the shipping service',
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+      'shipping_service_description' => array(
+        'description' => 'Description of the shipping service',
+        'type' => 'text',
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('shipping_service_id'),
+  );
+  
+  $schema['shipping_matrix_shipping_zone'] = array(
+    'description' => 'Table with zones belonging to a shipping service',
+    'fields' => array(
+      'shipping_zone_id' => array(
+        'description' => 'The unique identifier of the zone',
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'shipping_zone_shipping_service_id' => array(
+        'description' => 'The shipping service this zone belongs to.',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+      'shipping_zone_name' => array(
+        'description' => 'The name of the Zone',
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('shipping_zone_id', 'shipping_zone_shipping_service_id'),
+  );
+  
+  $schema['shipping_matrix_weight_table'] = array(
+    'description' => 'This table holds the price per weight',
+    'fields' => array(
+      'weight_table_id' => array(
+        'description' => 'unique identifier for this row',
+        'type' => 'serial',
+        'not null' => TRUE,
+      ),
+      'weight_table_zone_id' => array(
+        'description' => 'The zone id this weight belongs to',
+        'type' => 'int',
+        'not null' => TRUE,
+      ),
+    ),
+    'primary key' => array('weight_table_id', 'weight_table_zone_id'),
+  );
+  
+  return $schema;
+} 
+
+/**
+ * Implements hook_install().
+ */
+function commerce_shipping_matrix_install() {
+  // Create all the fields we are adding to our content type.
+  // http://api.drupal.org/api/function/field_create_field/7
+  foreach (_commerce_shipping_matrix_installed_fields() as $field) {
+    field_create_field($field);
+  }
+  
+  // Create all the instances for our fields.
+  // http://api.drupal.org/api/function/field_create_instance/7
+  // Attach fields to: shipping_matrix_services
+  foreach (_commerce_shipping_matrix_installed_instances() as $ikey => $instance) {
+    $instance['entity_type'] = 'shipping_matrix_services';
+    $instance['bundle'] = 'shipping_matrix_services';
+    if (in_array($ikey, array(
+      'shipping_matrix_max_dimensions', 
+      'shipping_matrix_max_shipping_weight', 
+      'shipping_matrix_base_price', 
+    ))) {
+      field_create_instance($instance);
+    }
+  }  
+  // attach fields to: shipping_matrix_zone
+  foreach (_commerce_shipping_matrix_installed_instances() as $ikey => $instance) {
+    $instance['entity_type'] = 'shipping_matrix_zone';
+    $instance['bundle'] = 'shipping_matrix_zone';
+
+    if (in_array($ikey, array(
+      'shipping_matrix_max_shipping_weight',
+      'shipping_matrix_base_price', 
+      'shipping_matrix_zone_locality', 
+    ))) {
+      field_create_instance($instance);
+    }
+  }
+  // attach fields to: shipping_matrix_weight_table
+  foreach (_commerce_shipping_matrix_installed_instances() as $ikey => $instance) {
+    $instance['entity_type'] = 'shipping_matrix_weight_table';
+    $instance['bundle'] = 'shipping_matrix_weight_table';
+    if (in_array($ikey, array(
+      'shipping_matrix_weight_price', 
+      'shipping_matrix_net_shipping_weight', 
+      'shipping_matrix_gross_shipping_weight', 
+    ))) {
+      field_create_instance($instance);
+    }
+  }
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function commerce_shipping_matrix_uninstall() {
+  // Delete fields.
+  $fields = array(
+    'shipping_matrix_services',
+		'shipping_matrix_addressfield_settings',
+		'shipping_matrix_calculation_settings',
+  );
+
+  foreach ($fields as $data) {
+    variable_del($data);
+  }
+  
+  // uninstall database tables
+  drupal_uninstall_schema('commerce_shipping_matrix');  
+  
+  // Loop over each of the fields defined by this module and delete
+  // all instances of the field, their data, and the field itself.
+  // http://api.drupal.org/api/function/field_delete_field/7
+  foreach (array_keys(_commerce_shipping_matrix_installed_fields()) as $field) {
+    field_delete_field($field);
+  }
+
+  // Loop over any remaining field instances attached to the node_example
+  // content type (such as the body field) and delete them individually.
+  // http://api.drupal.org/api/function/field_delete_field/7
+  foreach (_commerce_shipping_matrix_installed_instances() as $instance_name => $instance) {
+    field_delete_instance($instance);
+  }
+}
+
+
+/**
+ * Returns a structured array defining the fields created by this content type.
+ *
+ * This is factored into this function so it can be used in both
+ * commerce_shipping_matrix_install() and commerce_shipping_matrix_uninstall().
+ *
+ * @return
+ *  An associative array specifying the fields we wish to add to our
+ *  new entity type.
+ *
+ */
+function _commerce_shipping_matrix_installed_fields() {
+  $t = get_t();
+  return array(
+    'shipping_matrix_dimensions' => array(
+      'field_name'  => 'shipping_matrix_dimensions',
+      'cardinality' => 1,
+      'type'        => 'physical_dimensions',
+    ),
+    'shipping_matrix_weight' => array(
+      'field_name'  => 'shipping_matrix_weight',
+      'cardinality' => 1,
+      'type'        => 'physical_weight',
+    ),
+    'shipping_matrix_weight_gross' => array(
+      'field_name'  => 'shipping_matrix_weight_gross',
+      'cardinality' => 1,
+      'type'        => 'physical_weight',
+    ),
+    'shipping_matrix_price' => array(
+      'field_name'  => 'shipping_matrix_price',
+      'cardinality' => 1,
+      'type'        => 'commerce_price',
+    ),
+    'shipping_matrix_locality' => array(
+      'field_name'  => 'shipping_matrix_locality',
+      'cardinality' => -1,
+      'type'        => 'addressfield',
+    ),
+  );
+}
+
+/**
+ * Returns a structured array defining the instances for this entity.
+ *
+ * The instance lets Drupal know which widget to use to allow the user to enter
+ * data and how to react in different view modes.  
+ *
+ * This is factored into this function so it can be used in both
+ * joinprofile_install() and joinprofile_uninstall().
+ *
+ * @return
+ *  An associative array specifying the instances we wish to add to our new
+ *  entity type.
+ */
+function _commerce_shipping_matrix_installed_instances() {
+  $t = get_t();
+  return array(
+    'shipping_matrix_max_dimensions' => array(
+      'field_name'  => 'shipping_matrix_dimensions',
+      'label' => $t('Maximum shipping dimensions'),
+      'type' => 'physical_dimensions',
+      'required' => FALSE,
+      'widget' => array(
+        'weight' => '10',
+        'type' => 'physical_dimensions_textfields',
+        'module' => 'physical',
+        'active' => 1,
+        'settings' => array(
+          'default_unit' => 'mm',
+          'unit_select_list' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'physical_dimensions_formatted',
+          'settings' => array(),
+          'module' => 'physical',
+          'weight' => 1,
+        ),
+      ),
+      'description' => '',
+      'default_value' => NULL,
+    ),
+
+    'shipping_matrix_max_shipping_weight' => array(
+      'field_name' => 'shipping_matrix_weight',
+      'label' => $t('Maximum shipping weight'),
+      'type' => 'physical_weight',
+      'required' => FALSE,
+      'widget' => array(
+        'weight' => '8',
+        'type' => 'physical_weight_textfield',
+        'module' => 'physical',
+        'active' => 1,
+        'settings' => array(
+          'default_unit' => 'g',
+          'unit_select_list' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'physical_weight_formatted',
+          'settings' => array(),
+          'module' => 'physical',
+          'weight' => 2,
+        ),
+      ),
+    ),
+
+
+    'shipping_matrix_net_shipping_weight' => array(
+      'field_name' => 'shipping_matrix_weight',
+      'label' => $t('Net shipping weight'),
+      'type' => 'physical_weight',
+      'required' => TRUE,
+      'widget' => array(
+        'weight' => '8',
+        'type' => 'physical_weight_textfield',
+        'module' => 'physical',
+        'active' => 1,
+        'settings' => array(
+          'default_unit' => 'g',
+          'unit_select_list' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'physical_weight_formatted',
+          'settings' => array(),
+          'module' => 'physical',
+          'weight' => 2,
+        ),
+      ),
+    ),
+
+    'shipping_matrix_gross_shipping_weight' => array(
+      'field_name' => 'shipping_matrix_weight_gross',
+      'label' => $t('Gross shipping weight'),
+      'type' => 'physical_weight',
+      'required' => FALSE,
+      'widget' => array(
+        'weight' => '8',
+        'type' => 'physical_weight_textfield',
+        'module' => 'physical',
+        'active' => 1,
+        'settings' => array(
+          'default_unit' => 'g',
+          'unit_select_list' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'physical_weight_formatted',
+          'settings' => array(),
+          'module' => 'physical',
+          'weight' => 2,
+        ),
+      ),
+    ),
+
+    'shipping_matrix_base_price' => array(
+      'field_name' => 'shipping_matrix_price',
+      'label' => $t('Base shipping costs'),
+      'type' => 'commerce_price',
+      'required' => FALSE,
+      'widget' => array(
+        'type' => 'commerce_price_full',
+        'weight' => 6,
+        'settings' => array(
+          'currency_code' => 'default',
+        ),
+        'module' => 'commerce_price',
+      ),
+      'display' => array(
+        'display' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+        'default' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+        'node_teaser' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+      ),
+      'description' => '',
+    ),
+
+    'shipping_matrix_weight_price' => array(
+      'field_name' => 'shipping_matrix_price',
+      'label' => $t('Weight based shipping costs'),
+      'type' => 'commerce_price',
+      'required' => TRUE,
+      'widget' => array(
+        'type' => 'commerce_price_full',
+        'weight' => 6,
+        'settings' => array(
+          'currency_code' => 'default',
+        ),
+        'module' => 'commerce_price',
+      ),
+      'display' => array(
+        'display' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+        'default' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+        'node_teaser' => array(
+          'label' => 'hidden',
+          'type' => 'commerce_price_formatted_amount',
+          'settings' => array(
+            'calculation' => FALSE,
+          ),
+          'weight' => 0,
+          'module' => 'commerce_price',
+        ),
+      ),
+      'description' => '',
+    ),
+
+    'shipping_matrix_zone_locality' => array(
+      'field_name' => 'shipping_matrix_locality',
+        'label' => $t('Zone locality'),
+        'type' => 'addressfield',
+        'label' => 'Address',
+        'required' => FALSE,
+        'widget' => array(
+          'type' => 'addressfield_standard',
+          'weight' => 12,
+          'settings' => array(
+            'format_handlers' => array(
+              0 => 'address',
+              1 => 'name-oneline',
+            ),
+            'available_countries' => array(),
+          ),
+          'module' => 'addressfield',
+        ),
+        'display' => array(
+          'default' => array(
+            'label' => 'hidden',
+            'type' => 'addressfield_default',
+            'weight' => -10,
+            'settings' => array(
+            'use_widget_handlers' => 1,
+            'format_handlers' => array(
+              0 => 'address',
+            ),
+          ),
+          'module' => 'addressfield',
+        ),
+        'customer' => array(
+          'label' => 'hidden',
+          'type' => 'addressfield_default',
+          'weight' => -10,
+          'settings' => array(
+            'use_widget_handlers' => 1,
+            'format_handlers' => array(
+              0 => 'address',
+            ),
+          ),
+          'module' => 'addressfield',
+        ),
+        'administrator' => array(
+          'label' => 'hidden',
+          'type' => 'addressfield_default',
+          'weight' => -10,
+          'settings' => array(
+            'use_widget_handlers' => 1,
+            'format_handlers' => array(
+              0 => 'address',
+            ),
+          ),
+          'module' => 'addressfield',
+        ),
+      ),
+      'settings' => array(
+        'user_register_form' => FALSE,
+      ),
+      'description' => '',
+    ),  
+  );
+}
diff --git a/commerce_shipping_matrix.module b/commerce_shipping_matrix.module
new file mode 100644
index 0000000..e84c419
--- /dev/null
+++ b/commerce_shipping_matrix.module
@@ -0,0 +1,471 @@
+<?php
+/**
+ * @file
+ * Defines an shipping method for shipping by weight and country.
+ */
+
+// include entity controlers
+include_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'commerce_shipping_matrix') . '/commerce_shipping_matrix.controllers.inc';
+
+
+
+/**
+ * Implements hook_commerce_shipping_method_info().
+ */
+function commerce_shipping_matrix_commerce_shipping_method_info() {
+  $shipping_methods = array();
+  $shipping_methods['shipping_matrix'] = array(
+    'title' => t('Shipping Matrix'),
+    'description' => t('Shipping quote from shipping matrix.'),
+  );
+  return $shipping_methods;
+}
+
+
+
+/**
+ * Implements hook_commerce_shipping_service_info().
+ */
+function commerce_shipping_matrix_commerce_shipping_service_info() {
+  $shipping_services = array();
+  $available_services = _commerce_shipping_matrix_service_list();
+  $selected_services = variable_get('shipping_matrix_services', array());
+  foreach ($available_services as $id => $val) {
+    if ($val != 0) { // if you find a selected one...
+      $service = $available_services[$id];
+      $shipping_services[$service['slug']] = array(
+        'title' => t($service['title']),
+        'description' => t($service['description']),
+        'display_title' => t($service['title']),
+        'shipping_method' => 'shipping_matrix',
+        'price_component' => 'shipping',
+        'callbacks' => array(
+          'rate' => 'commerce_shipping_matrix_service_rate',
+        ),
+      );
+    }
+  }
+  return $shipping_services;
+}
+
+
+
+/**
+ * Function to get the created services services.
+ *
+ * @return
+ *   an array populated with the shipping_service_id
+ *   or incase empty an empry array
+ */
+function _commerce_shipping_matrix_service_list() {
+  $list = entity_load('shipping_matrix_services');
+  $services = array();
+  foreach ($list as $key => $service) {
+  $services[$service->shipping_service_id] = array(
+    'shipping_service_id' => $service->shipping_service_id,
+    'title' => t($service->shipping_service_name),
+    'description' => t($service->shipping_service_description),
+    );
+  }
+ // Make a unique ID to identify the service by
+  foreach ($services as $key => $service) {
+    $service['slug'] = 'shipping_matrix_service_id_' . $service['shipping_service_id'];
+    $services[$key] = $service;
+  }
+  return $services;
+}
+
+
+
+/**
+ * Function for retreiving the raw shipping service id
+ *
+ * @param $service
+ *   The shipping service id name
+ *
+ * @return
+ *   The raw numeric shipping service id;
+ *   FALSE if service raw value is not numeric
+ */
+function commerce_shipping_matrix_get_shipping_service_name($service) {
+  if (is_array($service)) {
+    $service = $service['base'];
+  }
+  $service = str_replace('shipping_matrix_service_id_', '', $service);
+  if (ctype_digit($service)) {
+    return $service;
+  }
+  return FALSE;
+}
+
+
+
+/**
+ * Loads the specified shipping service entity.
+ *
+ * @param $shipping_service
+ *   The shipping service id name
+ *
+ * @return
+ *   a loaded shipping service entity
+ */
+function commerce_shipping_matrix_get_shipping_service($shipping_service) {
+  $shipping_service = commerce_shipping_matrix_get_shipping_service_name($shipping_service);
+
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', 'shipping_matrix_services')
+    ->propertyCondition('shipping_service_id', $shipping_service);
+  $result = $query->execute();
+
+  if (isset($result['shipping_matrix_services'])) {
+    $shipping_matrix_services_nids = array_keys($result['shipping_matrix_services']);
+    $shipping_matrix_services = entity_load('shipping_matrix_services', $shipping_matrix_services_nids);
+  }
+  return $shipping_matrix_services;
+}
+
+
+
+/**
+ * Shipping service callback: returns a base price array for a shipping service
+ * calculated for the given order.
+ *
+ * @param $shipping_service
+ *   The shipping service id name
+ * @param $order
+ *   The order object
+ *
+ * @return
+ *   The amount as array 'amount', 'currency_code', 'data'
+ *   FALSE if amount is 0 or smaller
+ */
+function commerce_shipping_matrix_service_rate($shipping_service, $order) {
+  $shipping_matrix_services = commerce_shipping_matrix_get_shipping_service($shipping_service);
+  $key = key($shipping_matrix_services); // Returns the first key of it
+  $matrix_service_wrapper = entity_metadata_wrapper('shipping_matrix_services', $shipping_matrix_services[$key]);
+
+  $shipping_matrix_price = $matrix_service_wrapper->shipping_matrix_price->value();
+  //@TODO Maybe some sort options, cheapest ASC DESC, zone name ASC DESC, zone id ASC DESC?
+
+  // use shipping service as base currency
+  // setup componets to calculate total.
+  $components = $shipping_matrix_price;
+  $components['data']['components'][]['price'] = $shipping_matrix_price;
+
+  // Get the cost of the zone.
+  $zone_costs = _commerce_shipping_matrix_get_zone_cost($shipping_service, $order);
+  $calculation_settings = variable_get('shipping_matrix_calculation_settings', array());
+
+  // When we do not what the shipping service to be applicable if there are no
+  // matching zones.
+  if (empty($calculation_settings['shipping_matrix_zone_handling'])
+    || $calculation_settings['shipping_matrix_zone_handling'] != 'enabled') {
+    if (empty($zone_costs)) {
+      return array();
+    }
+  }
+
+
+  // If zone has costs add it to the components.
+  if (!empty($zone_costs)) {
+    //return FALSE;
+    //add zone cost to the components
+    foreach ($zone_costs['data']['components'] as $component) {
+      $components['data']['components'][] = $component;
+    }
+  }
+
+
+  $shipping_costs = commerce_price_component_total($components);
+
+  //if amount has a value return the amount
+  if ($shipping_costs['amount'] > 0) {
+    return array(
+      'amount' => $shipping_costs['amount'],
+      'currency_code' => $shipping_costs['currency_code'],
+      'data' => $shipping_costs['data'],
+    );
+  }
+  return FALSE;
+}
+
+
+
+// function for retreiving the shipping country of an order
+function _commerce_shipping_matrix_get_shipping_address($order) {
+  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+  $profile = $order_wrapper->commerce_customer_shipping->value();
+  if (empty($profile)) {
+    return;
+  }
+  $profile_entity = commerce_customer_profile_load_multiple(array($profile->profile_id));
+  $key = key($profile_entity);
+  $profile_wrapper = entity_metadata_wrapper('commerce_customer_profile', $profile_entity[$key]);
+  return $profile_wrapper->commerce_customer_address->value();
+}
+
+
+
+// function for retreiving the zones that are available for a country
+function _commerce_shipping_matrix_get_zone_cost($service_id, $order) {
+  // We need to make sure all calculataions in weight are in the same unit.
+  // So we setup a standard unit, i have chosen for grams.
+  $unit = 'g';
+  $components = array();
+
+  //@todo needs to change in addressfield... for comparing against other address fields
+  $shipping_address = _commerce_shipping_matrix_get_shipping_address($order);
+  $country = $shipping_address['country'];
+  $locality = $shipping_address['locality'];
+  $postal_code = $shipping_address['postal_code'];
+
+  // Total order weight.
+  $total_order_weight = commerce_physical_order_weight($order, $unit);
+  $calculation_settings = variable_get('shipping_matrix_calculation_settings', array());
+
+  // Get the zone information
+  //@todo change field condition to addressfield
+  $query = new EntityFieldQuery();
+  $query->entityCondition('entity_type', 'shipping_matrix_zone')
+    ->propertyCondition('shipping_zone_shipping_service_id', commerce_shipping_matrix_get_shipping_service_name($service_id))
+    ->fieldCondition('shipping_matrix_locality', 'country', $country, '=');
+  $result = $query->execute();
+
+  // get zone entity
+  if (isset($result['shipping_matrix_zone'])) {
+    $shipping_matrix_zone_nids = array_keys($result['shipping_matrix_zone']);
+    $shipping_matrix_zone = entity_load('shipping_matrix_zone', $shipping_matrix_zone_nids);
+    reset($shipping_matrix_zone); //Safety - sets pointer to top of array
+    $key = key($shipping_matrix_zone); // Returns the first key of it
+    $zone_wrapper = entity_metadata_wrapper('shipping_matrix_zone', $shipping_matrix_zone[$key]);
+
+    // Get and set the zone price
+    if (!empty($zone_wrapper->shipping_matrix_price->value())) {
+      $components = $zone_wrapper->shipping_matrix_price->value();
+      $components['data']['components'][]['price'] = $zone_wrapper->shipping_matrix_price->value();
+    }
+
+    // Get the table weight quote.
+
+    //@TODO: add sorting support multi-currency!!
+    $query = new EntityFieldQuery();
+    $query->entityCondition('entity_type', 'shipping_matrix_weight_table')
+      ->propertyCondition('weight_table_zone_id', $shipping_matrix_zone[$key]->shipping_zone_id, '=')
+      ->fieldOrderBy('shipping_matrix_price', 'amount', 'ASC');
+
+    $result = $query->execute();
+
+    if (isset($result['shipping_matrix_weight_table'])) {
+      $weight_table_ids = array_keys($result['shipping_matrix_weight_table']);
+      $weight_table = entity_load('shipping_matrix_weight_table', $weight_table_ids);
+
+      foreach ($weight_table as $row => $weight_option) {
+        $weight_wrapper = entity_metadata_wrapper('shipping_matrix_weight_table', $weight_option);
+        $tableweight_net = physical_weight_convert($weight_wrapper->shipping_matrix_weight->value(), $unit);
+        $tableweight_gross = physical_weight_convert($weight_wrapper->shipping_matrix_weight_gross->value(), $unit);
+
+        // Unset the non-applicable table weights for net weights.
+        if (empty($calculation_settings['shipping_matrix_net_gross']) || $calculation_settings['shipping_matrix_net_gross'] != 'gross') {
+          if ($tableweight_net['weight'] < $total_order_weight['weight']) {
+            unset($weight_table[$row]);
+          }
+          else {
+            $numbers[$row] = $weight_wrapper->shipping_matrix_price->value()['amount'];
+          }
+        }
+
+        // Unset the non-applicable table weights for gross weights.
+        else {
+          if ($tableweight_gross['weight'] < $total_order_weight['weight']) {
+            unset($weight_table[$row]);
+          }
+          else {
+            $numbers[$row] = $weight_wrapper->shipping_matrix_price->value()['amount'];
+          }
+        }
+      }
+
+      if (!empty($numbers)) {
+        // Get the key for the table row with the least amount.
+        if (empty($calculation_settings['shipping_matrix_weighttable_sort']) || $calculation_settings['shipping_matrix_weighttable_sort'] != 'max') {
+          $key = array_search(min($numbers), $numbers);
+        }
+
+        // Get the key for the table row with the max amount.
+        else {
+          $key = array_search(max($numbers), $numbers);
+        }
+
+        // Add weight table price component to total.
+        $selected_weight_wrapper = entity_metadata_wrapper('shipping_matrix_weight_table', $weight_table[$key]);
+        $components['data']['components'][]['price'] = $selected_weight_wrapper->shipping_matrix_price->value();
+      }
+
+    }
+  }
+
+  // Combine all components to one price.
+  if (!empty($components)) {
+    // Return total price amount.
+    return $components;
+  }
+
+  return FALSE;
+}
+
+/**
+ * Determines the maximum weight for this shipping service.
+ *
+ * @param $shipping_service
+ *   The shipping service id name
+ *
+ * @return
+ *   a physical field (weight) array with $max_weight['weight'] and $max_weight['unit']
+ *   the specified unit of measurement or empty array if no weight could be determined.
+ */
+function commerce_shipping_matrix_get_max_weight_shipping_service($shipping_service) {
+  $shipping_matrix_services = commerce_shipping_matrix_get_shipping_service($shipping_service);
+  reset($shipping_matrix_services); //Safety - sets pointer to top of array
+  $key = key($shipping_matrix_services); // Returns the first key of it
+  // get max weight for this shipping service
+  $max_weight = array();
+  $max_weight = $shipping_matrix_services[$key]->shipping_matrix_weight['und'][0];
+  return $max_weight;
+}
+
+
+
+/**
+ * Determines the maximum dimensions for this shipping service.
+ *
+ * @param $shipping_service
+ *   The shipping service id name
+ *
+ * @return
+ *   a physical field (dimension) array with $outerbox['length']
+ *   $outerbox['width'] $outerbox['height'] and $outerbox['unit']
+ *   the specified unit of measurement or empty array if no dimension
+ *   could be determined.
+ */
+function commerce_shipping_matrix_get_max_dimensions_shipping_service($shipping_service) {
+  $shipping_matrix_services = commerce_shipping_matrix_get_shipping_service($shipping_service);
+  reset($shipping_matrix_services); //Safety - sets pointer to top of array
+  $key = key($shipping_matrix_services); // Returns the first key of it
+  $outerbox = array();
+  // get max dimension for this shipping service
+  $outerbox = $shipping_matrix_services[$key]->shipping_matrix_dimensions['und'][0];
+  return $outerbox;
+}
+
+
+
+/**
+ * Shipping service callback: returns the example shipping service details form.
+ */
+function commerce_shipping_matrix_service_details_form($pane_form, $pane_values, $checkout_pane, $order, $shipping_service) {
+  $form = array();
+  $pane_values['service_details'] += array(
+    'name' => '',
+    'express' => '',
+  );
+  $form['name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Name'),
+    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
+    '#default_value' => $pane_values['service_details']['name'],
+    '#required' => TRUE,
+  );
+  $form['express'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Express delivery'),
+    '#description' => t('Express delivery (costs an additional E15)'),
+    '#default_value' => $pane_values['service_details']['express'],
+  );
+  return $form;
+}
+
+
+
+/**
+ * Shipping service callback: validates the example shipping service details.
+ */
+function commerce_shipping_matrix_service_details_form_validate($details_form, $details_values, $shipping_service, $order, $form_parents) {
+  if (drupal_strlen($details_values['name']) < 2) {
+    form_set_error(implode('][', array_merge($form_parents, array('name'))), t('You must enter a name two or more characters long.'));
+
+    // Even though the form error is enough to stop the submission of the form,
+    // it's not enough to stop it from a Commerce standpoint because of the
+    // combined validation / submission going on per-pane in the checkout form.
+    return FALSE;
+  }
+}
+
+
+
+/**
+ * Shipping service callback: increases the shipping line item's unit price if
+ * express delivery was selected.
+ */
+function commerce_shipping_matrix_service_details_form_submit($details_form, $details_values, $line_item) {
+  if ($details_values['express']) {
+    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+
+    // Build a price array for the express delivery fee.
+    $express_price = array(
+      'amount' => 1500,
+      'currency_code' => 'USD',
+      'data' => array(),
+    );
+
+  }
+}
+
+
+/**
+ * Implements hook_commerce_price_component_type_info().
+ */
+function commerce_shipping_matrix_commerce_price_component_type_info() {
+  return array(
+    'example_shipping_service_express' => array(
+      'title' => t('Express delivery'),
+      'weight' => 20,
+    ),
+  );
+}
+
+
+
+/**
+ * Implements hook_entity_info().
+ */
+function commerce_shipping_matrix_entity_info() {
+  return array(
+    'shipping_matrix_services' => array(
+      'label' => t('Shipping Matrix Shipping Service'),
+      'base table' => 'shipping_matrix_shipping_service',
+      'entity keys' => array(
+        'id' => 'shipping_service_id',
+      ),
+      'fieldable' => TRUE,
+      'controller class' => 'ShippingMatrixShippingServiceController',
+    ),
+    'shipping_matrix_zone' => array(
+      'label' => t('Shipping Matrix Zone'),
+      'base table' => 'shipping_matrix_shipping_zone',
+      'entity keys' => array(
+        'id' => 'shipping_zone_id',
+      ),
+      'fieldable' => TRUE,
+      'controller class' => 'ShippingMatrixZonesController',
+    ),
+    'shipping_matrix_weight_table' => array(
+      'label' => t('Shipping Matrix Weight Table'),
+      'base table' => 'shipping_matrix_weight_table',
+      'entity keys' => array(
+        'id' => 'weight_table_id',
+      ),
+      'fieldable' => TRUE,
+      'controller class' => 'ShippingMatrixTableWeightController',
+    ),
+  );
+}
diff --git a/commerce_shipping_matrix.rules.inc b/commerce_shipping_matrix.rules.inc
new file mode 100644
index 0000000..663b93b
--- /dev/null
+++ b/commerce_shipping_matrix.rules.inc
@@ -0,0 +1,400 @@
+<?php
+/**
+ * @file
+ * Defined rules for shipping matrix
+ */
+
+/**
+ * Determines the weight of an entire order.
+ *
+ * @param $max_weight
+ *   A weight field value array representing the total weight of a package in this service
+ * @param $order
+ *   The order object whose weight value should be calculated.
+ * @param $unit
+ *   The unit of measurement to use for the returned weight of the order.
+ *
+ * @return
+ *   true if all items of 
+ *   the specified unit of measurement or NULL if no weight could be determined.
+ */
+function commerce_shipping_matrix_order_max_weight($max_weight, $order, $unit = 'g') {
+  $max_weight = physical_weight_convert($max_weight, $unit);
+  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+  // var to check if at leas one items has weight
+  $ihm = FALSE;
+  // var to check if all items are smaller than the max weight
+  $smw = TRUE;
+  // Loop over each line item on the order.
+  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
+    // Get the weight value of product line items.
+    if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
+      $line_item_weight = commerce_physical_product_line_item_weight($line_item_wrapper->value());
+      // Add it to the running total converting it to the required weight unit.
+      if (!empty($line_item_weight['weight'])) {
+      $ihm = TRUE;
+        $converted_weight = physical_weight_convert($line_item_weight, $unit);
+    #drupal_set_message($max_weight['weight'] . ' < ' . $converted_weight['weight']);
+    if ($max_weight['weight'] < $converted_weight['weight']) {
+      $smw = FALSE;
+    }
+      }
+    }
+  }
+ // both needs to be true, at least one item has to have weight applied to it, and all items needs to be smallerd than the max allowed in a package.
+  if ($ihm === TRUE && $smw == TRUE) {
+  return TRUE;
+  }
+  return FALSE; 
+  }
+
+
+
+/**
+ * Checks if a box fits in another box.
+ *
+ * @param $outerbox
+ *   A dimension field value array including the 'length', 'width', 'height' and
+ *   'unit'.
+ * @param $innerbox
+ *   A dimension field value array including the 'length', 'width', 'height' and
+ *   'unit'.
+ *
+ * @return
+ *   True is the innerbox fits inside the outerbox
+ */
+function commerce_shipping_matrix_fits_dimension($outerbox, $innerbox, $unit = 'mm') { 
+  
+  // Convert dimensions to mm
+  $outerbox = physical_dimensions_convert($outerbox, $unit);
+  $innerbox = physical_dimensions_convert($innerbox, $unit);
+  
+  // Class to check if box fits in box
+  require_once('commerce_shipping_matrix.binpacking.inc');
+  $binpack = new boxing();
+  $binpack -> add_outer_box($outerbox['length'], $outerbox['width'], $outerbox['height']); // our quantum box; l, w, h
+  $binpack -> add_inner_box($innerbox['length'], $innerbox['width'], $innerbox['height']); // schroedingers cat; l, w, h
+  
+  // if box fits in box return true
+  try {
+   //@TODO undefined notice 
+   // suppres error for now
+  if (@$binpack -> fits()) return TRUE;
+  }  
+  catch (Exception $e) {
+  watchdog_exception($e);
+  }
+
+  return FALSE;
+}
+
+
+//---------------------------------------------
+
+// add shipping matrix values to rules
+function commerce_shipping_matrix_rules_data_info() {
+  return array(
+    'shippinh_matrix' => array(
+      'label' => t('Shipping Matrix - Shipping Service Values'),
+      'wrap' => TRUE,
+      'property info' => _commerce_shipping_matrix_shipping_service_values(),
+    ),
+  );  
+  
+}
+
+function _commerce_shipping_matrix_shipping_service_values() {
+  return array(
+    'type' => array(
+      'type' => 'text',
+      'label' => t('The category to which this message belongs'),
+    ),
+    'message' => array(
+      'type' => 'text',
+      'label' => ('Log message'),
+      'getter callback' => 'rules_system_log_get_message',
+      'sanitized' => TRUE,
+    ),
+    'severity' => array(
+      'type' => 'integer',
+      'label' => t('Severity'),
+      'options list' => 'watchdog_severity_levels',
+    ),
+    'request_uri' => array(
+      'type' => 'uri',
+      'label' => t('Request uri'),
+    ),
+    'link' => array(
+      'type' => 'text',
+      'label' => t('An associated, HTML formatted link'),
+    ),
+  );
+}
+
+
+//---------------------------------------------
+
+
+
+/**
+ * Implements hook_rules_condition_info().
+ */
+function commerce_shipping_matrix_rules_condition_info() {
+
+  $conditions = array();
+
+  
+
+  $conditions['shipping_matrix_rules_order_is_under_weight_limit_shipping_service'] = array(
+    'label' => t("Order's total weight is under the shipping service limit"),
+    'parameter' => array(
+      'commerce_order' => array(
+        'type' => 'commerce_order',
+        'label' => t('Order'),
+      ),
+        'shipping_service_name' => array(
+          'type' => 'text',
+          'label' => t('Shipping service'),
+          'options list' => 'commerce_shipping_service_options_list',
+        ),
+
+    ),
+    'group' => t('Shipping Matrix'),
+  );
+
+  $conditions['shipping_matrix_rules_order_maximum_dimension_is_under_maximum_shipping_service'] = array(
+    'label' => t("The maximum dimension of any product in the order is under the maximum of the shipping service"),
+    'parameter' => array(
+      'commerce_order' => array(
+        'type' => 'commerce_order',
+        'label' => t('Order'),
+      ),
+        'shipping_service_name' => array(
+          'type' => 'text',
+          'label' => t('Shipping service'),
+          'options list' => 'commerce_shipping_service_options_list',
+        ),
+    ),
+    'group' => t('Shipping Matrix'),
+  );
+
+
+
+/*
+ * THIS CAN BE DELETED AFTER COMMERCE_PHYSICAL IS UPDATED AND APPLIED #18 
+ * FROM ISSUE http://drupal.org/node/1344962
+ *
+ */
+
+$conditions['shipping_matrix_rules_order_is_under_weight_limit'] = array(
+    'label' => t("Order's total weight is under a chosen limit"),
+    'parameter' => array(
+      'commerce_order' => array(
+        'type' => 'commerce_order',
+        'label' => t('Order'),
+      ),
+      'limit' => array(
+        'type' => 'decimal',
+        'label' => t('Weight limit'),
+      ),
+      'unit' => array(
+        'type' => 'text',
+        'label' => t('Weight unit'),
+        'options list' => 'physical_weight_unit_options',
+        'restriction' => 'input',
+        'default value' => 'kg',
+      ),
+    ),
+    'group' => t('Commerce Physical'),
+  );
+
+
+  $conditions['shipping_matrix_rules_order_maximum_dimension_is_under_size'] = array(
+    'label' => t("The maximum dimension of any product in the order is under a certain size"),
+    'parameter' => array(
+      'commerce_order' => array(
+        'type' => 'commerce_order',
+        'label' => t('Order'),
+      ),
+      'limit' => array(
+        'type' => 'decimal',
+        'label' => t('Size limit'),
+      ),
+      'unit' => array(
+        'type' => 'text',
+        'label' => t('Dimension unit'),
+        'options list' => 'physical_dimension_unit_options',
+        'restriction' => 'input',
+        'default value' => 'cm',
+      ),
+    ),
+    'group' => t('Commerce Physical'),
+  );
+
+  $conditions['shipping_matrix_rules_order_is_shippable'] = array(
+    'label' => t("The order contains shippable products"),
+    'parameter' => array(
+      'commerce_order' => array(
+        'type' => 'commerce_order',
+        'label' => t('Order'),
+      ),
+    ),
+    'group' => t('Commerce Physical'),
+  );
+
+  return $conditions;
+}
+
+/**
+ * Rules condition: checks to see if the given order's total weight is under the 
+ * shipping service limit.
+ */
+function commerce_shipping_matrix_rules_order_is_under_weight_limit_shipping_service($order, $shipping_service) {
+  
+  // we need a unit in wich we can compare
+  $unit = 'g';
+  
+  $shipping_weight = commerce_shipping_matrix_get_max_weight_shipping_service($shipping_service);
+  $shipping_weight = physical_weight_convert($shipping_weight, $unit);
+
+  //drupal_set_message($shipping_service, 'warning'); 
+  $order_weight = commerce_physical_order_weight($order, $unit);
+
+
+  return $order_weight['weight'] <= $shipping_weight['weight'];
+}
+
+
+
+
+function commerce_shipping_matrix_rules_order_maximum_dimension_is_under_maximum_shipping_service($order, $shipping_service) {
+  $unit = 'mm';
+  // Get max dimension from shipping service
+  $max_dimension = commerce_shipping_matrix_get_max_dimensions_shipping_service($shipping_service);  
+  $product_dimensions = commerce_shipping_matrix_order_dimensions($order, $unit);
+  // Get the dimensions of every product in the order
+  foreach ($product_dimensions as $dimension) {
+    //drupal_set_message('<pre>'. print_r($dimension, true) . ' is smaller than ' . print_r($max_dimension, true) . '</pre>', 'warning');
+    // Check each of length / width / height
+    if (commerce_shipping_matrix_fits_dimension($max_dimension, $dimension) === FALSE) {
+      return FALSE;
+      }
+    }
+  return TRUE;
+  }
+
+
+
+
+
+
+
+
+
+/*
+ * THIS CAN BE DELETED AFTER COMMERCE_PHYSICAL IS UPDATED AND APPLIED #18 
+ *  FROM ISSUE http://drupal.org/node/1344962
+ *
+ */
+
+function commerce_shipping_matrix_product_line_item_dimensions($line_item) {
+  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
+  $dimensions = NULL;
+
+  // If the line item references a valid product...
+  if (!empty($line_item_wrapper->commerce_product)) {
+    $product = $line_item_wrapper->commerce_product->value();
+
+    if (!empty($product)) {
+      // If the product has a valid dimensions field...
+      $field_name = commerce_physical_entity_dimensions_field_name('commerce_product', $product);
+
+      if (!empty($field_name) && !empty($product->{$field_name})) {
+        // Extract the dimensions value from the product.
+        $product_wrapper = entity_metadata_wrapper('commerce_product', $product);
+        $dimensions[] = $product_wrapper->{$field_name}->value();
+      }
+    }
+  }
+
+  // Allow other modules to alter the volume if necessary.
+
+  return $dimensions;
+}
+
+
+
+
+
+/**
+ * Rules condition: checks to see if the maximum dimension of any product in the
+ * order is under a certain size
+ */
+function commerce_shipping_matrix_rules_order_maximum_dimension_is_under_size($order, $limit, $unit) {
+
+  $max_dimension = 0;
+
+  $dimension_keys = array(
+    'length',
+    'width',
+    'height',
+  );
+
+  // Get the dimensions of every product in the order
+  foreach (commerce_shipping_matrix_order_dimensions($order, $unit) as $dimension) {
+
+    // Check each of length / width / height
+    foreach ($dimension_keys as $dimension_key) {
+
+      // If this dimension's bigger than the current max, it's the new max.
+      if ($dimension[$dimension_key] > $max_dimension) {
+        $max_dimension = $dimension[$dimension_key];
+      }
+    }
+  }
+
+  return $max_dimension <= $limit;
+}
+
+/**
+ * Rules condition: checks to see if the given order's total weight is under a
+ * certain limit.
+ */
+function commerce_shipping_matrix_rules_order_is_under_weight_limit($order, $limit, $unit) {
+
+  $order_weight = commerce_physical_order_weight($order, $unit);
+
+  return $order_weight['weight'] <= $limit;
+}
+
+
+/**
+ * Rules condition: check if the order contains shippable products.
+ */
+function commerce_shipping_matrix_rules_order_is_shippable($order) {
+  return commerce_physical_order_shippable($order);
+}
+
+
+
+function commerce_shipping_matrix_order_dimensions($order, $unit = 'mm') {
+  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+  $order_dimensions = array();
+  // Loop over each line item on the order.
+  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
+
+    // Get the weight value of product line items.
+    if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
+
+  $line_item_dimensions = commerce_shipping_matrix_product_line_item_dimensions($line_item_wrapper->value());
+
+      $order_dimensions = array_merge($order_dimensions, $line_item_dimensions);
+      }
+    }
+
+  // Now ensure that all dimensions supplied are in the requested units
+  foreach ($order_dimensions as $key => $dimensions) {
+    $order_dimensions[$key] = physical_dimensions_convert($dimensions, $unit);
+  }
+  return $order_dimensions;
+  }
diff --git a/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.info b/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.info
new file mode 100644
index 0000000..1331376
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.info
@@ -0,0 +1,8 @@
+name = Commerce Shipping Matrix UI
+description = Provides a UI for the Shipping Matrix method.
+package = Commerce (shipping)
+dependencies[] = commerce_shipping_matrix
+dependencies[] = entity
+core = 7.x
+
+
diff --git a/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.module b/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.module
new file mode 100644
index 0000000..5c352c8
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/commerce_shipping_matrix_ui.module
@@ -0,0 +1,200 @@
+<?php
+
+/**
+ * @file
+ * Takes care of the UI for the shipping matrix
+ */
+
+/**
+ * Implements hook_menu().
+ */
+function commerce_shipping_matrix_ui_menu() {
+  $items = array();
+  $items['admin/commerce/config/shipping/shipping-matrix'] = array(
+    'title' => 'Shipping Matrix',
+    'page callback' => 'commerce_shipping_matrix_ui_shippingservice_admin_page',
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.shippingservice.inc',
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 2,
+  );
+  // 'Edit' tab for shipping services.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/edit'] = array(
+    'title' => 'Shipping Service',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('commerce_shipping_matrix_ui_shippingservice_form', 5),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.shippingservice.inc',
+  );
+  // Add Shipping service.
+  $items['admin/commerce/config/shipping/services/shipping-matrix/add'] = array(
+    'title' => 'Add a Shipping Matrix Shipping Service',
+    'page callback' => 'commerce_shipping_matrix_ui_shippingservice_add',
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.shippingservice.inc',
+    'type' => MENU_LOCAL_ACTION,
+  );
+  $items['admin/commerce/config/shipping/shipping-matrix/add'] = array(
+    'title' => 'Add a Shipping Matrix Shipping Service',
+    'page callback' => 'commerce_shipping_matrix_ui_shippingservice_add',
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.shippingservice.inc',
+    'type' => MENU_LOCAL_ACTION,
+  );
+  // Shipping service settings.
+  $items['admin/commerce/config/shipping/shipping-matrix/settings'] = array(
+    'title' => 'Settings',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('commerce_shipping_matrix_ui_settings_form'),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.settings.inc',
+    'type' => MENU_LOCAL_ACTION,
+  );
+
+  // 'Zones' tab for adding zones to shipping services.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/zones'] = array(
+    'title' => 'Zones',
+    'page callback' => 'commerce_shipping_matrix_ui_zones_admin_page',
+    'page arguments' => array(5),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.zones.inc',
+  );
+  // Add a Zones to a shipping service.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/zones/add'] = array(
+    'title' => 'Add zone',
+    'page callback' => 'commerce_shipping_matrix_ui_zones_add',
+    'page arguments' => array(5),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.zones.inc',
+    'type' => MENU_LOCAL_ACTION,
+  );
+  // Edit a zone for a shipping service.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/zones/%'] = array(
+    'title' => 'Edit zone',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('commerce_shipping_matrix_ui_zones_form', 7, 5),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.zones.inc',
+  );
+
+  // Configure the weights for a zone.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/zones-table/%'] = array(
+    'title' => 'Weight Table',
+    'page callback' => 'commerce_shipping_matrix_ui_weight_table_admin_page',
+    'page arguments' => array(7, 5),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.weighttable.inc',
+  );
+
+  // Add weights to a zone.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/zones-table/%/add'] = array(
+    'title' => 'Add Weight Table row',
+    'page callback' => 'commerce_shipping_matrix_ui_weight_table_add',
+    'page arguments' => array(5, 7),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.weighttable.inc',
+    'type' => MENU_LOCAL_ACTION,
+  );
+
+  // Add a Zones to a shipping service.
+  $items['admin/commerce/config/shipping/shipping-matrix/%/%/%'] = array(
+    'title' => 'Add Weight Table row',
+    'page callback' => 'commerce_shipping_matrix_ui_weight_table_edit',
+    'page arguments' => array(5, 6, 7),
+    'access arguments' => array('administer shipping'),
+    'file' => 'includes/commerce_shipping_matrix_ui.weighttable.inc',
+  );
+
+  return $items;
+
+
+  // Add a Ajax for deleting.
+  /*
+  $items['shipping_matrix/ajax'] = array(
+    'title' => 'Remove item callback',
+    'page callback' => 'commerce_shipping_matrix_ui_remove_js',
+    'delivery callback' => 'ajax_deliver',
+    'access callback' => TRUE,
+    'theme callback' => 'ajax_base_page_theme',
+    'type' => MENU_CALLBACK,
+    'file path' => 'includes',
+    'file' => 'form.inc',
+  );
+  */
+}
+
+
+function commerce_shipping_matrix_ui_remove_js() {
+  // drupal_html_id() very helpfully ensures that all html IDS are unique
+  // on a page. Unfortunately what it doesn't realize is that the IDs
+  // we are generating are going to replace IDs that already exist, so
+  // this actually works against us.
+  if (isset($_POST['ajax_html_ids'])) {
+    unset($_POST['ajax_html_ids']);
+  }
+
+  list($form, $form_state) = ajax_get_form();
+  drupal_process_form($form['#form_id'], $form, $form_state);
+
+  // Get the information on what we're removing.
+  $button = $form_state['triggering_element'];
+
+  // Go two levels up in the form, to the whole widget.
+  $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -3));
+
+  // Now send back the proper AJAX command to replace it.
+  $return = array(
+    '#type' => 'ajax',
+    '#commands' => array(
+      ajax_command_replace('#' . $element['#id'], drupal_render($element))
+    ),
+  );
+
+  // Because we're doing this ourselves, messages aren't automatic. We have
+  // to add them.
+  $messages = theme('status_messages');
+  if ($messages) {
+    $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
+  }
+
+  return $return;
+}
+
+
+/**
+ * Delete unneccesary address fields from zones form.
+ */
+function commerce_shipping_matrix_ui_form_commerce_shipping_matrix_ui_zones_form_alter(&$form, $form_state) {
+
+  //@TODO Maybe make this more efficient and also when there are custom fields added
+
+  // Add our js.
+  drupal_add_js(drupal_get_path('module','commerce_shipping_matrix_ui') . '/includes/remove_button.js');
+
+
+  // Delete form elements.
+  $language = $form['shipping_matrix_locality']['#language'];
+  foreach ($form['shipping_matrix_locality'][$language] as $localkey => $locality) {
+    if (is_int($localkey)) {
+      // Add a remove button.
+      $form['shipping_matrix_locality'][$language][$localkey]['remove_button'] = array(
+      // '#name' => $form['shipping_matrix_locality'][$language][$localkey][$fieldkey]['#field_name'].'_'.$form['shipping_matrix_locality'][$language][$localkey][$fieldkey]['#delta'].'_remove_button',
+        '#type' => 'markup',
+        '#value' => t('Remove'),
+        '#validate' => array(),
+        '#markup' => '<div class="unlimitedfield_remove_button">' . t('[x] Remove') . '</div>',
+        '#weight' => -99,
+      );
+
+    }
+  }
+}
+
+/**
+ * Implements hook_addressfield_default_values_alter().
+ *
+ * Ensure default country is always empty to avoid extra countries being added accidentally on edits.
+ */
+function commerce_shipping_matrix_ui_addressfield_default_values_alter(&$default_values, $context) {
+  $default_values['country'] = '';
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.weighttable_ui.inc b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.weighttable_ui.inc
new file mode 100644
index 0000000..4c10139
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.weighttable_ui.inc
@@ -0,0 +1,215 @@
+<?php
+
+/**
+ * Returns a administration page for Matrix Shipping services.
+ */
+function commerce_shipping_matrix_ui_weight_table_admin_page($shipping_service, $zone) {
+  $content = array();
+  $content['table'] = commerce_shipping_matrix_ui_weight_table_list_entities($shipping_service, $zone);
+
+  return $content;
+}
+
+/**
+ * Returns a render array with all Matrix Shipping services.
+ */
+function commerce_shipping_matrix_ui_weight_table_list_entities($shipping_service, $zone) {
+  $content = array();
+
+  // Load all shipping matrix shipping services.
+  $query = new EntityFieldQuery();
+  $entities = $query->entityCondition('entity_type', 'shipping_matrix_weight_table')
+                    //->entityCondition('bundle', 'shipping_matrix_zone')
+                    ->propertyCondition('weight_table_zone_id', $shipping_service)
+                    //->fieldCondition('field_date', 'value', array('2011-03-01', '2011-03-31'), 'BETWEEN')
+                    //->fieldOrderBy('field_date', 'value', 'ASC')
+                    ->execute();
+
+
+
+  if (!empty($entities)) {
+    $entities = commerce_shipping_matrix_ui_weight_table_load_multiple(array_keys($entities['shipping_matrix_weight_table']));
+
+    foreach ($entities as $entity) {
+      $ops[0] = array(
+        'data' => array(
+          'edit' => l(t('edit'), 'admin/commerce/config/shipping/shipping-matrix/' . $shipping_service . '/' . $zone . '/' . $entity->weight_table_id . '/edit'),
+        ),
+        'no_striping' => true
+      );
+      $operations = array(
+        '#theme' => 'table',
+        '#rows' => $ops
+      );
+
+      $rows[] = array(
+        'data' => array(
+          'id' => $entity->weight_table_id,
+          'weight' => isset($entity->shipping_matrix_weight) ? physical_weight_format($entity->shipping_matrix_weight['und'][0]) : '',
+          'weight_gross' => isset($entity->shipping_matrix_weight_gross) ? physical_weight_format($entity->shipping_matrix_weight_gross['und'][0]) : '',
+          'weight_price' =>  isset($entity->shipping_matrix_price) ? commerce_currency_format($entity->shipping_matrix_price['und'][0]['amount'], $entity->shipping_matrix_price['und'][0]['currency_code']) : '',
+          'operations' =>  drupal_render($operations),
+        ),
+      );
+    }
+    $content['entity_table'] = array(
+      '#theme' => 'table',
+      '#rows' => $rows,
+      '#header' => array(t('ID'), t('Net Weight'), t('Gross Weight'), t('Weight-based shipping cost'), t('Operations')),
+    );
+  }
+  else {
+    $content[] = array(
+      '#type' => 'item',
+      '#markup' => t('No weight rows currently exist.'),
+    );
+  }
+  return $content;
+}
+
+function commerce_shipping_matrix_ui_weight_table_load_multiple($basic_ids = FALSE, $conditions = array(), $reset = FALSE) {
+  return entity_load('shipping_matrix_weight_table', $basic_ids, $conditions, $reset);
+}
+
+/**
+ * Provides a wrapper on the edit form to add a new entity.
+ */
+function commerce_shipping_matrix_ui_weight_table_edit($shipping_service, $zone, $table) {
+  // Create a basic entity structure to be used and passed to the validation
+  // and submission functions.
+  return drupal_get_form('commerce_shipping_matrix_ui_weight_table_form', $table, $shipping_service, $zone);
+}
+
+
+
+/**
+ * Provides a wrapper on the edit form to add a new entity.
+ */
+function commerce_shipping_matrix_ui_weight_table_add($shipping_service, $zone) {
+  // Create a basic entity structure to be used and passed to the validation
+  // and submission functions.
+  $entity = entity_get_controller('shipping_matrix_weight_table')->create();
+  return drupal_get_form('commerce_shipping_matrix_ui_weight_table_form', $entity, $shipping_service, $zone);
+}
+
+/**
+ * Form function to create an entity_example_basic entity.
+ *
+ * The pattern is:
+ * - Set up the form for the data that is specific to your
+ *   entity: the columns of your base table.
+ * - Call on the Field API to pull in the form elements
+ *   for fields attached to the entity.
+ */
+function commerce_shipping_matrix_ui_weight_table_form($form, &$form_state, $entity, $shipping_service = false, $zone = false) {
+  // Load entity by id, if entity is passed as id.
+  if (!is_object($entity) && ctype_digit($shipping_service) && ctype_digit($zone)) {
+    $entities = commerce_shipping_matrix_ui_weight_table_load_multiple(array($entity));
+    if (empty($entities[$entity])) {
+      drupal_set_message(t('Weight table %id not found', array('%id' => $entity)));
+      drupal_goto('admin/commerce/config/shipping/shipping-matrix');
+      return;
+    }
+    $entity = $entities[$entity];
+  }
+
+  $entity->weight_table_shipping_id = !empty($entity->weight_table_shipping_id) ? $entity->weight_table_shipping_id : $shipping_service;
+  $entity->weight_table_zone_id = !empty($entity->weight_table_zone_id) ? $entity->weight_table_zone_id : $zone;
+
+  // Load entity in form.
+  $form['basic_entity'] = array(
+    '#type' => 'value',
+    '#value' => $entity,
+  );
+
+  // Confirm deletion.
+  if (isset($form_state['storage']) && $form_state['storage']['ask_confirm'] ) {
+    $form['basic_entity'] = array(
+      '#type' => 'value',
+      '#value' => $entity,
+    );
+    $question = t('Are you sure you want to delete this weight table?');
+    $path = current_path();
+    $description = t('This cannot be undone.');
+    $yes = t('Confirm');
+    $no = t('Cancel');
+    return confirm_form($form, $question, $path, $description, $yes, $no);
+  }
+
+
+  // Not deleting the service, show the standard form.
+  // Attach fields by this entity.
+  field_attach_form('shipping_matrix_weight_table', $entity, $form, $form_state);
+
+
+  // Attach buttons to this form.
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 100,
+  );
+  $form['delete'] = array(
+    '#type' => 'submit',
+    '#value' => t('Delete'),
+    '#weight' => 200,
+  );
+
+  return $form;
+}
+
+
+/**
+ * Validation handler for entity_example_basic_add_form form.
+ * We pass things straight through to the Field API to handle validation
+ * of the attached fields.
+ */
+function commerce_shipping_matrix_ui_weight_table_form_validate($form, &$form_state) {
+  //field_attach_form_validate('shipping_matrix_ui_weight_table', $form_state['values']['basic_entity'], $form, $form_state);
+}
+
+
+/**
+ * Form submit handler: submits basic_add_form information
+ */
+function commerce_shipping_matrix_ui_weight_table_form_submit($form, &$form_state) {
+  // Delete button clicked, rebuild the form to display confirmation prompt.
+  if ($form_state['clicked_button']['#value'] == t('Delete')) {
+    $form_state['rebuild'] = TRUE;
+    $form_state['storage']['ask_confirm'] = TRUE;
+  }
+  // Deletion confirmed.
+  elseif (isset($form_state['values']['confirm']) && $form_state['values']['confirm']) {
+    commerce_shipping_matrix_ui_weight_table_delete($form, $form_state);
+  }
+  // Save the service.
+  else {
+    $entity = $form_state['values']['basic_entity'];
+    //$entity->weight_table_zone_id = $entity->weight_table_zone_id;
+    field_attach_submit('shipping_matrix_weight_table', $entity, $form, $form_state);
+
+    drupal_set_message(t('Submitted'));
+    $entity = commerce_shipping_matrix_ui_weight_table_save($entity);
+    $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix/' . $entity->weight_table_shipping_id . '/zones-table/' . $entity->weight_table_zone_id;
+  }
+}
+
+function commerce_shipping_matrix_ui_weight_table_save(&$entity) {
+  return entity_get_controller('shipping_matrix_weight_table')->save($entity);
+}
+
+/**
+ * Delete function for form submit
+ */
+function commerce_shipping_matrix_ui_weight_table_delete($form, &$form_state) {
+  $entity = $form_state['values']['basic_entity'];
+  $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix/' . $entity->weight_table_shipping_id . '/zones-table/' . $entity->weight_table_zone_id;
+  $entity = commerce_shipping_matrix_ui_weight_table_del($entity);
+  drupal_set_message(t('Shipping service deleted'));
+}
+
+/**
+ * Delete shipping service entity
+ */
+function commerce_shipping_matrix_ui_weight_table_del(&$entity) {
+  return entity_get_controller('shipping_matrix_weight_table')->delete($entity);
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.zones_ui.inc b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.zones_ui.inc
new file mode 100644
index 0000000..17af1a3
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix.zones_ui.inc
@@ -0,0 +1,230 @@
+<?php
+
+
+/**
+ * Returns a administration page for Matrix shipping zones.
+ */
+function commerce_shipping_matrix_ui_zones_admin_page($shipping_service) {
+  $content = array();
+  $content['table'] = commerce_shipping_matrix_ui_zones_list_entities($shipping_service);
+
+  return $content;
+}
+
+/**
+ * Returns a render array with all Matrix shipping zones.
+ */
+function commerce_shipping_matrix_ui_zones_list_entities($shipping_service) {
+  $content = array();
+
+  // Load all shipping matrix shipping zones.
+  $query = new EntityFieldQuery();
+  $entities = $query->entityCondition('entity_type', 'shipping_matrix_zone')
+                    ->propertyCondition('shipping_zone_shipping_service_id', $shipping_service)
+                    //->fieldCondition('field_date', 'value', array('2011-03-01', '2011-03-31'), 'BETWEEN')
+                    //->fieldOrderBy('field_date', 'value', 'ASC')
+                    ->execute();
+  if (!empty($entities)) {
+    $entities = commerce_shipping_matrix_ui_zones_load_multiple(array_keys($entities['shipping_matrix_zone']));
+    foreach ($entities as $entity) {
+      $ops[0] = array(
+        'data' => array(
+          'edit' => l(t('edit this zone'), 'admin/commerce/config/shipping/shipping-matrix/' . $shipping_service . '/zones/' . $entity->shipping_zone_id),
+          'zone' => l(t('edit shipping weight table'), 'admin/commerce/config/shipping/shipping-matrix/' . $shipping_service . '/zones-table/' . $entity->shipping_zone_id),
+        ),
+        'no_striping' => true
+      );
+      $operations = array(
+        '#theme' => 'table',
+        '#rows' => $ops
+      );
+
+      $entity_wrapper = entity_metadata_wrapper('shipping_matrix_zone', $entity);
+      $base_price = $entity_wrapper->shipping_matrix_price->value();
+      //$max_dimensions = $entity_wrapper->shipping_max_shipping_dimensions->value();
+      $max_weight = $entity_wrapper->shipping_matrix_weight->value();
+      $rows[] = array(
+        'data' => array(
+          'id' => $entity->shipping_zone_id,
+          'item_description' => $entity->shipping_zone_name,
+          'default_rate' =>  !empty($base_price) ? commerce_currency_format($base_price['amount'], $base_price['currency_code']) : '',
+       //   'max_dimensions' =>  !empty($max_dimensions) ? physical_dimensions_format($max_dimensions) : '',
+          'max_weight' =>  !empty($max_weight) ? physical_weight_format($max_weight) : '',
+          'operations' => drupal_render($operations),
+        ),
+      );
+    }
+    $content['entity_table'] = array(
+      '#theme' => 'table',
+      '#rows' => $rows,
+      //'#header' => array(t('ID'), t('Shipping zone'), t('Basic Shipping Rate'), t('Max Dimensions'), t('Max Weight'), t('Opperations')),
+      '#header' => array(t('ID'), t('Shipping zone'), t('Basic Shipping Rate'), t('Max Weight'), t('Opperations')),
+    );
+  }
+  else {
+    $content[] = array(
+      '#type' => 'item',
+      '#markup' => t('No Matrix shipping zone currently exist.'),
+    );
+  }
+  return $content;
+}
+
+function commerce_shipping_matrix_ui_zones_load_multiple($basic_ids = FALSE, $conditions = array(), $reset = FALSE) {
+  return entity_load('shipping_matrix_zone', $basic_ids, $conditions, $reset);
+}
+
+
+/**
+ * Provides a wrapper on the edit form to add a new entity.
+ */
+function commerce_shipping_matrix_ui_zones_add($shipping_service) {
+  // Create a basic entity structure to be used and passed to the validation
+  // and submission functions.
+  $entity = entity_get_controller('shipping_matrix_zone')->create();
+  return drupal_get_form('commerce_shipping_matrix_ui_zones_form', $entity, $shipping_service);
+}
+
+/**
+ * Form function to create an entity_example_basic entity.
+ *
+ * The pattern is:
+ * - Set up the form for the data that is specific to your
+ *   entity: the columns of your base table.
+ * - Call on the Field API to pull in the form elements
+ *   for fields attached to the entity.
+ */
+function commerce_shipping_matrix_ui_zones_form($form, &$form_state, $entity, $shipping_service) {
+  // Load entity by id, if entity is passed as id.
+  if (!is_object($entity) && ctype_digit($entity)) {
+    $entities = commerce_shipping_matrix_ui_zones_load_multiple(array($entity));
+    $entity = $entities[$entity];
+  }
+
+  // Confirm deletion.
+  if (isset($form_state['storage']) && $form_state['storage']['ask_confirm'] ) {
+    $form['basic_entity'] = array(
+      '#type' => 'value',
+      '#value' => $entity,
+    );
+    $question = t('Are you sure you want to delete this zone?');
+    $path = current_path();
+    $description = t('This cannot be undone.');
+    $yes = t('Confirm');
+    $no = t('Cancel');
+    return confirm_form($form, $question, $path, $description, $yes, $no);
+  }
+
+
+  // Not deleting the zone, show the standard form.
+  $form['shipping_zone_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Shipping zone name'),
+    '#required' => TRUE,
+    '#default_value' => !empty($entity->shipping_zone_name) ? $entity->shipping_zone_name : '',
+  );
+  $form['shipping_service'] = array(
+    '#type' => 'hidden',
+    '#value' => $shipping_service,
+  );
+
+/*
+  $form['shipping_zone_description'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Shipping zone description'),
+    '#required' => false,
+    '#default_value' => !empty($entity->shipping_service_description) ? $entity->shipping_service_description : '',
+  );
+*/
+
+  // Load entity in form.
+  $form['basic_entity'] = array(
+    '#type' => 'value',
+    '#value' => $entity,
+  );
+  // Attach fields by this entity.
+  field_attach_form('shipping_matrix_zone', $entity, $form, $form_state);
+
+  $language = $form['shipping_matrix_locality']['#language'];
+  $delta = $form['shipping_matrix_locality'][$language]['#max_delta'];
+  // Provide an empty field on new zones, but remove the empty one when editing
+  // existing zones.
+  if ($delta != 0) {
+    $form['shipping_matrix_locality'][$language]['#max_delta'] = $delta - 1;
+    unset($form['shipping_matrix_locality'][$language][$delta]);
+  }
+
+  // Attach buttons to this form.
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 100,
+  );
+  $form['delete'] = array(
+    '#type' => 'submit',
+    '#value' => t('Delete'),
+    '#weight' => 200,
+  );
+
+  return $form;
+}
+
+
+/**
+ * Validation handler for entity_example_basic_add_form form.
+ * We pass things straight through to the Field API to handle validation
+ * of the attached fields.
+ */
+function commerce_shipping_matrix_ui_zones_form_validate($form, &$form_state) {
+  //field_attach_form_validate('shipping_matrix_zones', $form_state['values']['basic_entity'], $form, $form_state);
+}
+
+
+/**
+ * Form submit handler: submits basic_add_form information.
+ */
+function commerce_shipping_matrix_ui_zones_form_submit($form, &$form_state) {
+  // Delete button clicked, rebuild the form to display confirmation prompt.
+  if ($form_state['clicked_button']['#value'] == t('Delete')) {
+    $form_state['rebuild'] = TRUE;
+    $form_state['storage']['ask_confirm'] = TRUE;
+  }
+  // Deletion confirmed.
+  elseif (isset($form_state['values']['confirm']) && $form_state['values']['confirm']) {
+    commerce_shipping_matrix_ui_zones_delete($form, $form_state);
+  }
+  // Save the zone.
+  else {
+    $entity = $form_state['values']['basic_entity'];
+    $entity->shipping_zone_name = $form_state['values']['shipping_zone_name'];
+    $entity->shipping_zone_shipping_service_id = $form_state['values']['shipping_service'];
+
+    //$entity->shipping_service_description = $form_state['values']['shipping_service_description'];
+    field_attach_submit('shipping_matrix_zone', $entity, $form, $form_state);
+    drupal_set_message(t('Submitted'));
+    $entity = commerce_shipping_matrix_ui_zones_save($entity);
+    $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix/' . $form_state['values']['shipping_service'] . '/zones';
+  }
+}
+
+function commerce_shipping_matrix_ui_zones_save(&$entity) {
+  return entity_get_controller('shipping_matrix_zone')->save($entity);
+}
+
+/**
+ * Delete function for zones form submit.
+ */
+function commerce_shipping_matrix_ui_zones_delete($form, &$form_state) {
+  $entity = $form_state['values']['basic_entity'];
+  $shipping_service = $entity->shipping_zone_shipping_service_id;
+  $entity = commerce_shipping_matrix_ui_zones_del($entity);
+  drupal_set_message(t('Shipping zone deleted'));
+  $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix/' . $shipping_service . '/zones';
+}
+
+/**
+ * Delete shipping zone entity.
+ */
+function commerce_shipping_matrix_ui_zones_del(&$entity) {
+  return entity_get_controller('shipping_matrix_zone')->delete($entity);
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.admin.inc b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.admin.inc
new file mode 100644
index 0000000..2f19888
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.admin.inc
@@ -0,0 +1,349 @@
+<?php
+
+/**
+ * @file
+ * Handles admin settings page for Shippiong Matrix module.
+ */
+
+/* hook_settings_form() */
+function commerce_shipping_matrix_ui_settings_form($form, &$form_state) {
+  $ups_link = l(t('UPS.com'), 'https://www.ups.com/upsdeveloperkit', array('attributes' => array('target' => '_blank')));
+  $form['api'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('UPS API credentials'),
+    '#collapsible' => TRUE,
+    '#description' => t('In order to obtain shipping rate estimates, you must have an account with UPS. You can apply for UPS API credentials at !ups', array('!ups' => $ups_link)),
+  );
+
+
+  $form['api']['commerce_ups_account_id'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Account ID'),
+    '#default_value' => $api_vars['ups_accountid'],
+    '#required' => TRUE,
+  );
+  $form['api']['commerce_ups_user_id'] = array(
+    '#type' => 'textfield',
+    '#title' => t('User ID'),
+    '#default_value' => $api_vars['ups_userid'],
+    '#required' => TRUE,
+  );
+  $form['api']['commerce_ups_password'] = array(
+    '#type' => 'password',
+    '#title' => t('Password'),
+    '#required' => !variable_get('commerce_ups_password', FALSE),
+    '#description' => t('Please leave blank if you do not want to update your password at this time.'),
+  );
+  $form['api']['commerce_ups_access_key'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Access Key'),
+    '#default_value' => $api_vars['ups_accesskey'],
+    '#required' => TRUE,
+  );
+  $form['api']['encryption'] = array(
+    '#type' => 'item',
+    '#title' => t('Encryption'),
+    'status' => array(
+      '#type' => 'item',
+      '#title' => FALSE,
+    ),
+  );
+  $form['origin']['commerce_ups_company_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Company Name'),
+    '#default_value' => variable_get('commerce_ups_company_name')
+  );
+  $form['origin']['commerce_ups_address_line_1'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Address'),
+    '#default_value' => variable_get('commerce_ups_address_line_1')
+  );
+  $form['origin']['commerce_ups_address_line_2'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Address (Additional)'),
+    '#default_value' => variable_get('commerce_ups_address_line_2')
+  );
+  $form['origin']['commerce_ups_city'] = array(
+    '#type' => 'textfield',
+    '#title' => t('City'),
+    '#default_value' => variable_get('commerce_ups_city')
+  );
+  $form['origin']['commerce_ups_state'] = array(
+    '#type' => 'select',
+    '#title' => t('State'),
+    '#default_value' => variable_get('commerce_ups_state'),
+    '#options' => array(
+      '' => t('Please Select'),
+      'AL' => t('Alabama'),
+      'AK' => t('Alaska'),
+      'AZ' => t('Arizona'),
+      'AR' => t('Arkansas'),
+      'CA' => t('California'),
+      'CO' => t('Colorado'),
+      'CT' => t('Connecticut'),
+      'DE' => t('Delaware'),
+      'DC' => t('District of Columbia'),
+      'FL' => t('Florida'),
+      'GA' => t('Georgia'),
+      'HI' => t('Hawaii'),
+      'ID' => t('Idaho'),
+      'IL' => t('Illinois'),
+      'IN' => t('Indiana'),
+      'IA' => t('Iowa'),
+      'KS' => t('Kansas'),
+      'KY' => t('Kentucky'),
+      'LA' => t('Louisiana'),
+      'ME' => t('Maine'),
+      'MD' => t('Maryland'),
+      'MA' => t('Massachusetts'),
+      'MI' => t('Michigan'),
+      'MN' => t('Minnesota'),
+      'MS' => t('Mississippi'),
+      'MO' => t('Missouri'),
+      'MY' => t('Montana'),
+      'NE' => t('Nebraska'),
+      'NV' => t('Nevada'),
+      'NH' => t('New Hampshire'),
+      'NJ' => t('New Jersey'),
+      'NM' => t('New Mexico'),
+      'NY' => t('New York'),
+      'NC' => t('North Carolina'),
+      'ND' => t('North Dakota'),
+      'OH' => t('Ohio'),
+      'OK' => t('Oklahoma'),
+      'OR' => t('Oregon'),
+      'PA' => t('Pennsylvania'),
+      'RI' => t('Rhode Island'),
+      'SC' => t('South Carolina'),
+      'SD' => t('South Dakota'),
+      'TN' => t('Tennessee'),
+      'TX' => t('Texas'),
+      'UT' => t('Utah'),
+      'VT' => t('Vermont'),
+      'VA' => t('Virginia'),
+      'WA' => t('Washington'),
+      'WV' => t('West Virginia'),
+      'WI' => t('Wisconsin'),
+      'WY' => t('Wyoming'),
+    )
+  );
+  $form['origin']['commerce_ups_postal_code'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Postal Code'),
+    '#size' => 5,
+    '#default_value' => variable_get('commerce_ups_postal_code')
+  );
+  $form['origin']['commerce_ups_country_code'] = array(
+    '#type' => 'select',
+    '#title' => t('Country'),
+    '#default_value' => variable_get('commerce_ups_country_code'),
+    '#options' => array(
+      '' => t('Please Select'),
+      'US' => t('United States of America'),
+    )
+  );
+  $form['services'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Enable UPS Shipping Services'),
+    '#collapsible' => TRUE,
+  );
+
+  $form['services']['commerce_ups_services'] = array(
+    '#type' => 'checkboxes',
+    '#options' => $array_options,
+    '#default_value' => variable_get('commerce_ups_services', array())
+  );
+  $form['packaging'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Enable UPS Packaging Types'),
+    '#collapsible' => FALSE,
+  );
+  $form['packaging']['commerce_ups_packaging_explanation'] = array(
+    '#type' => 'markup',
+    '#markup' => t('Only "Customer supplied packaging" is currently available. Please enter the package size below.'),
+  );
+  $form['packaging']['commerce_ups_packaging'] = array(
+    '#type' => 'hidden',
+    '#value' => '02',
+  );
+  /*
+  $form['packaging']['commerce_ups_packaging'] = array(
+    '#type' => 'checkboxes',
+    '#options' => _commerce_ups_packaging_types(),
+    '#default_value' => variable_get('commerce_ups_packaging', array())
+  );
+  */
+  // Fields for default package size (inches)
+  $form['default_package_size'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Package size (inches)'),
+    '#collapsible' => FALSE,
+    '#description' => 'UPS requires a package size when determining estimates.',
+  );
+  $form['default_package_size']['commerce_ups_default_package_size_length'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Length'),
+    '#size' => 5,
+    '#required' => TRUE,
+    '#default_value' => variable_get('commerce_ups_default_package_size_length'),
+  );
+  $form['default_package_size']['commerce_ups_default_package_size_width'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Width'),
+    '#size' => 5,
+    '#required' => TRUE,
+    '#default_value' => variable_get('commerce_ups_default_package_size_width'),
+  );
+  $form['default_package_size']['commerce_ups_default_package_size_height'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Height'),
+    '#size' => 5,
+    '#required' => TRUE,
+    '#default_value' => variable_get('commerce_ups_default_package_size_height'),
+  );
+  $form['default_package_size']['details'] = array(
+    '#markup' => 'The package size is used to determine the number of packages necessary to
+      create a UPS shipping cost estimate. <strong>If products do not have physical dimensions and
+      weights associated with them, the estimates will not be accurate.</strong> The logic implemented works as:
+      <ul>
+      <li>Assume each order requires at least one package.</li>
+      <li>Use the combined volume of all products in an order to determine the number of packages.</li>
+      </ul>
+      This is a simple calculation that can get close to actual shipping costs. More
+      complex logic involving multiple package sizes, weights, and void space can be implemented via
+      custom modules.
+      <br/><br/>
+      UPS has a ' . l('maximum package size', 'http://www.ups.com/content/us/en/resources/prepare/oversize.html', array('attributes' => array('target' => '_blank'))) . '.',
+  );
+  $form['commerce_ups_pick_up_schedule'] = array(
+    '#type' => 'select',
+    '#title' => t('Pick-up Schedule'),
+    '#default_value' => variable_get('commerce_ups_pick_up_schedule')
+  );
+  $form['commerce_ups_shipto_residential'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Calculate ALL ship to addresses as residential.'),
+    '#default_value' => variable_get('commerce_ups_shipto_residential', 0),
+  );
+  $form['commerce_ups_show_logo'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show UPS Logo on Shipping Page'),
+    '#default_value' => variable_get('commerce_ups_show_logo', 0),
+  );
+  $form['actions']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save configuration'),
+  );
+  return $form;
+}
+
+/*
+ * Implements hook_form_validate().
+ */
+function commerce_shipping_matrix_ui_settings_form_validate($form, &$form_state) {
+  $values = $form_state['values'];
+  
+  // Ensure the default package size is less than the maximum (http://www.ups.com/content/us/en/resources/prepare/oversize.html)
+  //  Length (longest side) <= 108 inches
+  //  Girth = 2*width + 2*height
+  //  Length + Girth <= 165 inches
+  $dimensions = array($values['commerce_ups_default_package_size_length'],
+                      $values['commerce_ups_default_package_size_width'],
+                      $values['commerce_ups_default_package_size_height']);
+  sort($dimensions);
+  list($height, $width, $length) = $dimensions;
+  $girth = 2*$width + 2*$height;
+  if ($length > 108) {
+    form_set_error('commerce_ups_default_package_size_length', t('The greatest dimension of the package size must be 108 inches or less.'));
+  }
+  if ($length + $girth > 165) {
+    form_set_error('commerce_ups_default_package_size_length', t('The girth (2*width + 2*height) of the package size must be 165 inches or less.'));
+  }
+
+  $encrypted = variable_get('commerce_ups_encrypt', FALSE) && function_exists('aes_decrypt');
+
+  // If the Password field is empty, then they're not trying to update it and we should ignore it.
+  if (empty($values['commerce_ups_password'])) {
+    unset($form_state['values']['commerce_ups_password']);
+    if ($encrypted && empty($form_state['input']['commerce_ups_password'])) {
+      form_set_error('commerce_ups_password', t('You must enter in a password to turn off encryption.'));
+    }
+    return;
+  }
+  
+  /* If we are setting or resetting values, test the connection.
+  $ups_connection = ups_api_function_here();
+  if (is_good_connection($ups_connection)) {
+    drupal_set_message(t('Connection established. UPS credentials updated.'));
+  }
+  else {
+    drupal_set_message(
+      t('Resetting UPS credentials failed.'), 'error');
+    form_set_error('commerce_ups_account_id', t('Unable to connect to UPS. Please check your credentials.'));
+    form_set_error('commerce_ups_user_id');
+    form_set_error('commerce_ups_access_key');
+    form_set_error('commerce_ups_password');
+  }
+  */
+}
+
+/*
+ * Implements hook_form_submit().
+ */
+function commerce_shipping_matrix_ui_settings_form_submit($form, &$form_state) {
+  $encrypted = variable_get('commerce_ups_encrypt', FALSE) && function_exists('aes_decrypt');
+  // Encrypt the UPS API credentials if available
+  if (isset($form_state['input']['commerce_ups_encrypt']) && $form_state['input']['commerce_ups_encrypt']) {
+    $form_state['input']['commerce_ups_user_id'] = commerce_ups_encrypt($form_state['input']['commerce_ups_user_id']);
+    $form_state['input']['commerce_ups_account_id'] = commerce_ups_encrypt($form_state['input']['commerce_ups_account_id']);
+    $form_state['input']['commerce_ups_access_key'] = commerce_ups_encrypt($form_state['input']['commerce_ups_access_key']);
+    if (!empty($form_state['input']['commerce_ups_password'])) {
+      $form_state['input']['commerce_ups_password'] = commerce_ups_encrypt($form_state['input']['commerce_ups_password']);
+    }
+    elseif ($encrypted == FALSE) {
+      // This is an odd case, if encryption is turned on but the password is already in the db
+      // Then we need to pull it from the db, not from the field
+      $form_state['input']['commerce_ups_password'] = commerce_ups_encrypt(variable_get('commerce_ups_password', ''));
+    }
+  }
+
+  if (empty($form_state['input']['commerce_ups_password'])) {
+    unset($form_state['input']['commerce_ups_password']);
+  }
+
+  if (!isset($form_state['input']['commerce_ups_encrypt'])) {
+    $form_state['input']['commerce_ups_encrypt'] = FALSE;
+  }
+
+  $fields = array(
+    'commerce_ups_account_id',
+    'commerce_ups_user_id',
+    'commerce_ups_password',
+    'commerce_ups_access_key',
+    'commerce_ups_encrypt',
+    'commerce_ups_services',
+    'commerce_ups_company_name',
+    'commerce_ups_address_line_1',
+    'commerce_ups_address_line_2',
+    'commerce_ups_city',
+    'commerce_ups_state',
+    'commerce_ups_postal_code',
+    'commerce_ups_country_code',
+    'commerce_ups_packaging',
+    'commerce_ups_pick_up_schedule',
+    'commerce_ups_show_logo',
+    'commerce_ups_default_package_size_length',
+    'commerce_ups_default_package_size_width',
+    'commerce_ups_default_package_size_height',
+    'commerce_ups_shipto_residential',
+  );
+
+  foreach ($fields as $key) {
+    if (array_key_exists($key, $form_state['input'])) {
+      $value = $form_state['input'][$key];
+      variable_set($key, $value);
+    }
+  }
+
+  drupal_set_message(t('The UPS configuration options have been saved.'));
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.settings.inc b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.settings.inc
new file mode 100644
index 0000000..ae9a778
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.settings.inc
@@ -0,0 +1,135 @@
+<?php
+
+
+/**
+ * Form function to create an entity_example_basic entity.
+ *
+ * The pattern is:
+ * - Set up the form for the data that is specific to your
+ *   entity: the columns of your base table.
+ * - Call on the Field API to pull in the form elements
+ *   for fields attached to the entity.
+ */
+function commerce_shipping_matrix_ui_settings_form($form, &$form_state) {
+  $form['#tree'] = TRUE;  // Prevent flattening the form values
+  // addressfield implementation:
+  // Get default fields
+  // @TODO Maybe get also user defined fields??
+
+  $form['shipping_matrix_addressfield_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Addressfield Settings'),
+    '#description' => t('Select here the addressfield(s) the shipping calculator needs to check for in a zone'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+
+  $addressfield_settings = variable_get('shipping_matrix_addressfield_settings', array());
+  foreach (addressfield_default_values() as $fieldname => $defaultvalue) {
+    // Make county mandatory
+    // We atleast want this value, Addressfields considers every address field empty if it has no country
+    if ($fieldname == 'country') {
+      $form['shipping_matrix_addressfield_settings'][$fieldname] = array(
+        '#type' => 'checkbox',
+        '#title' => t($fieldname),
+        '#default_value' => (!empty($addressfield_settings[$fieldname]))
+                            ? $addressfield_settings[$fieldname]
+                            : TRUE,
+        '#disabled' => TRUE,
+        '#description' => t('The country must be enabled because of the nature of the addressfield'),
+      );
+    }
+    else {
+      $form['shipping_matrix_addressfield_settings'][$fieldname] = array(
+        '#type' => 'checkbox',
+        '#title' => t($fieldname),
+        '#default_value' => (!empty($addressfield_settings[$fieldname]))
+                            ? $addressfield_settings[$fieldname]
+                            : FALSE,
+      );
+    }
+  }
+
+
+  $form['shipping_matrix_calculation_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Calculation Settings'),
+    '#description' => t('Here you can change some preferences in calculation'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+
+
+  $shipping_matrix_calculation_settings = variable_get('shipping_matrix_calculation_settings', array());
+
+  $form['shipping_matrix_calculation_settings']['shipping_matrix_zone_sort'] = array(
+    '#type' => 'radios',
+    '#title' => t('Zone handling'),
+    '#default_value' => (!empty($shipping_matrix_calculation_settings['shipping_matrix_zone_sort']))
+                        ? $shipping_matrix_calculation_settings['shipping_matrix_zone_sort']
+                        : 'min',
+    '#options' => array('min' => t('Zone with the least price amount'), 'max' => t('Zone with the most price amount')),
+    '#description' => t('At shipping calculation, we can choose to charge the cheapest zone or the most expensive one.'),
+  );
+
+  $form['shipping_matrix_calculation_settings']['shipping_matrix_weighttable_sort'] = array(
+    '#type' => 'radios',
+    '#title' => t('Weight table handling'),
+    '#default_value' => (!empty($shipping_matrix_calculation_settings['shipping_matrix_weighttable_sort']))
+                        ? $shipping_matrix_calculation_settings['shipping_matrix_weighttable_sort']
+                        : 'min',
+    '#options' => array('min' => t('Weight row with the least price amount'), 'max' => t('Weight row with the most price amount')),
+    '#description' => t('At shipping calculation, we can choose to charge the cheapest weight row or the most expensive one.'),
+  );
+
+
+  $form['shipping_matrix_calculation_settings']['shipping_matrix_net_gross'] = array(
+    '#type' => 'radios',
+    '#title' => t('Weight field used for calculations'),
+    '#default_value' => (!empty($shipping_matrix_calculation_settings['shipping_matrix_net_gross']))
+                        ? $shipping_matrix_calculation_settings['shipping_matrix_net_gross']
+                        : 'net',
+    '#options' => array('net' => t('Netto weight field'), 'gross' => t('Gross weight field')),
+    '#description' => t('At shipping calculation, we can use netto weights or gross weights for calculation.'),
+  );
+
+  $form['shipping_matrix_calculation_settings']['shipping_matrix_zone_handling'] = array(
+    '#type' => 'radios',
+    '#title' => t('Shipping services without zones'),
+    '#default_value' => (!empty($shipping_matrix_calculation_settings['shipping_matrix_zone_handling']))
+                        ? $shipping_matrix_calculation_settings['shipping_matrix_zone_handling']
+                        : 'disabled',
+    '#options' => array('disabled' => t('Disable shippingservice when no zones are applicable'), 'enabled' => t('Enable shipping service with no applicable zones')),
+    '#description' => t('If you enabled this, the shipping servie rate will be applied even if there are no zones returned.'),
+  );
+
+
+  //drupal_set_message(print_r($shipping_matrix_calculation_settings, true), 'warning');
+
+  return system_settings_form($form);
+}
+
+
+/**
+ * Validation handler for entity_example_basic_add_form form.
+ * We pass things straight through to the Field API to handle validation
+ * of the attached fields.
+ */
+function commerce_shipping_matrix_ui_settings_form_validate($form, &$form_state) {
+  //field_attach_form_validate('shipping_matrix_ui_shippingservice', $form_state['values']['basic_entity'], $form, $form_state);
+}
+
+
+/**
+ * Form submit handler: submits basic_add_form information
+ */
+function commerce_shipping_matrix_ui_settings_form_submit($form, &$form_state) {
+  $entity = $form_state['values']['basic_entity'];
+  $entity->shipping_service_name = $form_state['values']['shipping_service_name'];
+  $entity->shipping_service_description = $form_state['values']['shipping_service_description'];
+  field_attach_submit('shipping_matrix_services', $entity, $form, $form_state);
+  drupal_set_message(t('Submitted'));
+  $entity = commerce_shipping_matrix_ui_shippingservice_save($entity);
+  $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix';
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.shippingservice.inc b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.shippingservice.inc
new file mode 100644
index 0000000..70d3cd7
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/commerce_shipping_matrix_ui.shippingservice.inc
@@ -0,0 +1,218 @@
+<?php
+
+/**
+ * Returns a administration page for Matrix Shipping services.
+ */
+function commerce_shipping_matrix_ui_shippingservice_admin_page() {
+  $content = array();
+  $content['table'] = commerce_shipping_matrix_ui_shippingservice_list_entities();
+  return $content;
+}
+
+/**
+ * Returns a render array with all Matrix Shipping services.
+ */
+function commerce_shipping_matrix_ui_shippingservice_list_entities() {
+  $content = array();
+
+  // Load all shipping matrix shipping services.
+  $entities = commerce_shipping_matrix_ui_shippingservice_load_multiple();
+
+  if (!empty($entities)) {
+    foreach ($entities as $entity) {
+      // Set operations for this shipping service
+      $ops[0] = array(
+        'data' => array(
+          'edit' => l(t('edit shipping service'), 'admin/commerce/config/shipping/shipping-matrix/' . $entity->shipping_service_id . '/edit'),
+          'zone' => l(t('zone overview'), 'admin/commerce/config/shipping/shipping-matrix/' . $entity->shipping_service_id . '/zones'),
+        ),
+        'no_striping' => true
+      );
+      $operations = array(
+        '#theme' => 'table',
+        '#rows' => $ops
+      );
+      $entity_wrapper = entity_metadata_wrapper('shipping_matrix_services', $entity);
+      $price = $entity_wrapper->shipping_matrix_price->value();
+      $dimensions = $entity_wrapper->shipping_matrix_dimensions->value();
+      $weight = $entity_wrapper->shipping_matrix_weight->value();
+      $rows[] = array(
+        'data' => array(
+          'id' => $entity->shipping_service_id,
+          'item_description' => $entity->shipping_service_name,
+          'zones' => $entity->shipping_service_id,
+          'default_rate' => !empty($price) ? commerce_currency_format($price['amount'], $price['currency_code']) : '',
+          'max_dimensions' => !empty($dimensions) ? physical_dimensions_format($dimensions) : '',
+          'max_weight' => !empty($weight) ? physical_weight_format($weight) : '',
+          'operations' => drupal_render($operations),
+        ),
+      );
+    }
+    $content['entity_table'] = array(
+      '#theme' => 'table',
+      '#rows' => $rows,
+      '#header' => array(t('ID'), t('Shipping Service'), t('Zones'), t('Basic Shipping Rate'), t('Max Dimensions'), t('Max Weight'), t('Opperations')),
+    );
+  }
+  else {
+    $content[] = array(
+      '#type' => 'item',
+      '#markup' => t('No Matrix Shipping Service currently exist.'),
+    );
+  }
+  return $content;
+}
+
+function commerce_shipping_matrix_ui_shippingservice_load_multiple($basic_ids = FALSE, $conditions = array(), $reset = FALSE) {
+  return entity_load('shipping_matrix_services', $basic_ids, $conditions, $reset);
+}
+
+
+/**
+ * Provides a wrapper on the edit form to add a new entity.
+ */
+function commerce_shipping_matrix_ui_shippingservice_add() {
+  // Create a basic entity structure to be used and passed to the validation
+  // and submission functions.
+  $entity = entity_get_controller('shipping_matrix_services')->create();
+  return drupal_get_form('commerce_shipping_matrix_ui_shippingservice_form', $entity);
+}
+
+/**
+ * Form function to create an entity_example_basic entity.
+ *
+ * The pattern is:
+ * - Set up the form for the data that is specific to your
+ *   entity: the columns of your base table.
+ * - Call on the Field API to pull in the form elements
+ *   for fields attached to the entity.
+ */
+function commerce_shipping_matrix_ui_shippingservice_form($form, &$form_state, $entity) {
+  // Load entity by id, if entity is passed as id.
+  if (!is_object($entity) && ctype_digit($entity)) {
+    $entities = commerce_shipping_matrix_ui_shippingservice_load_multiple(array($entity));
+    if (empty($entities[$entity])) {
+      drupal_set_message(t('Shipping service %id not found', array('%id' => $entity)));
+      drupal_goto('admin/commerce/config/shipping/shipping-matrix');
+      return;
+    }
+    $entity = $entities[$entity];
+  }
+
+  // Confirm deletion.
+  if (isset($form_state['storage']) && $form_state['storage']['ask_confirm'] ) {
+    $form['basic_entity'] = array(
+      '#type' => 'value',
+      '#value' => $entity,
+    );
+    $question = t('Are you sure you want to delete this shipping service?');
+    $path = current_path();
+    $description = t('This cannot be undone.');
+    $yes = t('Confirm');
+    $no = t('Cancel');
+    return confirm_form($form, $question, $path, $description, $yes, $no);
+  }
+
+
+  // Not deleting the service, show the standard form.
+  $form['shipping_service_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Shipping Service Name'),
+    '#required' => TRUE,
+    '#default_value' => !empty($entity->shipping_service_name) ? $entity->shipping_service_name : '',
+  );
+  $form['shipping_service_description'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Shipping Service Description'),
+    '#required' => false,
+    '#default_value' => !empty($entity->shipping_service_description) ? $entity->shipping_service_description : '',
+  );
+
+  // Load entity in form.
+  $form['basic_entity'] = array(
+    '#type' => 'value',
+    '#value' => $entity,
+  );
+  // Attach fields by this entity.
+  field_attach_form('shipping_matrix_services', $entity, $form, $form_state);
+
+  // Attach buttons to this form.
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+    '#weight' => 100,
+  );
+  $form['delete'] = array(
+    '#type' => 'submit',
+    '#value' => t('Delete'),
+    '#weight' => 200,
+  );
+
+  return $form;
+}
+
+
+/**
+ * Validation handler for entity_example_basic_add_form form.
+ * We pass things straight through to the Field API to handle validation
+ * of the attached fields.
+ */
+function commerce_shipping_matrix_ui_shippingservice_form_validate($form, &$form_state) {
+  //field_attach_form_validate('shipping_matrix_ui_shippingservice', $form_state['values']['basic_entity'], $form, $form_state);
+}
+
+
+/**
+ * Form submit handler: submits basic_add_form information
+ */
+function commerce_shipping_matrix_ui_shippingservice_form_submit($form, &$form_state) {
+  // Delete button clicked, rebuild the form to display confirmation prompt.
+  if ($form_state['clicked_button']['#value'] == t('Delete')) {
+    $form_state['rebuild'] = TRUE;
+    $form_state['storage']['ask_confirm'] = TRUE;
+  }
+  // Deletion confirmed.
+  elseif (isset($form_state['values']['confirm']) && $form_state['values']['confirm']) {
+    commerce_shipping_matrix_ui_shippingservice_delete($form, $form_state);
+  }
+  // Save the service.
+  else {
+    $entity = $form_state['values']['basic_entity'];
+    $entity->shipping_service_name = $form_state['values']['shipping_service_name'];
+    $entity->shipping_service_description = $form_state['values']['shipping_service_description'];
+    field_attach_submit('shipping_matrix_services', $entity, $form, $form_state);
+    drupal_set_message(t('Submitted'));
+
+    $entity = commerce_shipping_matrix_ui_shippingservice_save($entity);
+    $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix';
+  }
+}
+
+function commerce_shipping_matrix_ui_shippingservice_save(&$entity) {
+  $controller = entity_get_controller('shipping_matrix_services')->save($entity);
+
+  // Clear caches and rebuild the menu items.
+  commerce_shipping_services_reset();
+  entity_defaults_rebuild();
+  rules_clear_cache(TRUE);
+  menu_rebuild();
+
+  return $controller;
+}
+
+/**
+ * Delete function for form submit.
+ */
+function commerce_shipping_matrix_ui_shippingservice_delete($form, &$form_state) {
+  $entity = $form_state['values']['basic_entity'];
+  $entity = commerce_shipping_matrix_ui_shippingservice_del($entity);
+  drupal_set_message(t('Shipping service deleted'));
+  $form_state['redirect'] = 'admin/commerce/config/shipping/shipping-matrix';
+}
+
+/**
+ * Delete shipping service entity
+ */
+function commerce_shipping_matrix_ui_shippingservice_del(&$entity) {
+  return entity_get_controller('shipping_matrix_services')->delete($entity);
+}
diff --git a/modules/commerce_shipping_matrix_ui/includes/remove_button.js b/modules/commerce_shipping_matrix_ui/includes/remove_button.js
new file mode 100644
index 0000000..3662f21
--- /dev/null
+++ b/modules/commerce_shipping_matrix_ui/includes/remove_button.js
@@ -0,0 +1,35 @@
+// JavaScript Document
+jQuery('document').ready(function(){
+  jQuery('div.form-wrapper').delegate('.unlimitedfield_remove_button', 'click', function(){
+    // get parent table row
+    var row = jQuery(this).closest('td').parent('tr');
+
+    // hide and empty values
+    jQuery(row).hide();
+    jQuery(row).find('input').val('');
+    jQuery(row).find('select').val('');
+    jQuery(row).find('textarea').text('');
+    jQuery(row).find('checkbox').removeAttr('checked');
+    jQuery(row).find('options').removeAttr('selected');
+
+    jQuery(row).find('select').val('');
+		
+		// set addressbook value to first 
+		var addressfield =  jQuery(row).find('select')
+		var option = addressfield.jQuery(" option:first").val();
+		 addressfield.val(option);
+		 addressfield.click();
+
+  
+    // fix table row classes
+    var table_id = jQuery(row).parent('tbody').parent('table').attr('id');
+    jQuery('#'+table_id+' tr.draggable:visible').each(function(index, element){
+      jQuery(element).removeClass('odd').removeClass('even');
+      if((index%2) == 0){
+        jQuery(element).addClass('odd');
+      } else {
+        jQuery(element).addClass('even');
+      }
+    });
+  });
+});
\ No newline at end of file
diff --git a/modules/includes/shipping_matrix.admin.inc b/modules/includes/shipping_matrix.admin.inc
deleted file mode 100644
index 0abaa30..0000000
--- a/modules/includes/shipping_matrix.admin.inc
+++ /dev/null
@@ -1,349 +0,0 @@
-<?php
-
-/**
- * @file
- * Handles admin settings page for Shippiong Matrix module.
- */
-
-/* hook_settings_form() */
-function shipping_matrix_ui_settings_form($form, &$form_state) {
-  $ups_link = l(t('UPS.com'), 'https://www.ups.com/upsdeveloperkit', array('attributes' => array('target' => '_blank')));
-  $form['api'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('UPS API credentials'),
-    '#collapsible' => TRUE,
-    '#description' => t('In order to obtain shipping rate estimates, you must have an account with UPS. You can apply for UPS API credentials at !ups', array('!ups' => $ups_link)),
-  );
-
-
-  $form['api']['commerce_ups_account_id'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Account ID'),
-    '#default_value' => $api_vars['ups_accountid'],
-    '#required' => TRUE,
-  );
-  $form['api']['commerce_ups_user_id'] = array(
-    '#type' => 'textfield',
-    '#title' => t('User ID'),
-    '#default_value' => $api_vars['ups_userid'],
-    '#required' => TRUE,
-  );
-  $form['api']['commerce_ups_password'] = array(
-    '#type' => 'password',
-    '#title' => t('Password'),
-    '#required' => !variable_get('commerce_ups_password', FALSE),
-    '#description' => t('Please leave blank if you do not want to update your password at this time.'),
-  );
-  $form['api']['commerce_ups_access_key'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Access Key'),
-    '#default_value' => $api_vars['ups_accesskey'],
-    '#required' => TRUE,
-  );
-  $form['api']['encryption'] = array(
-    '#type' => 'item',
-    '#title' => t('Encryption'),
-    'status' => array(
-      '#type' => 'item',
-      '#title' => FALSE,
-    ),
-  );
-  $form['origin']['commerce_ups_company_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Company Name'),
-    '#default_value' => variable_get('commerce_ups_company_name')
-  );
-  $form['origin']['commerce_ups_address_line_1'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Address'),
-    '#default_value' => variable_get('commerce_ups_address_line_1')
-  );
-  $form['origin']['commerce_ups_address_line_2'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Address (Additional)'),
-    '#default_value' => variable_get('commerce_ups_address_line_2')
-  );
-  $form['origin']['commerce_ups_city'] = array(
-    '#type' => 'textfield',
-    '#title' => t('City'),
-    '#default_value' => variable_get('commerce_ups_city')
-  );
-  $form['origin']['commerce_ups_state'] = array(
-    '#type' => 'select',
-    '#title' => t('State'),
-    '#default_value' => variable_get('commerce_ups_state'),
-    '#options' => array(
-      '' => t('Please Select'),
-      'AL' => t('Alabama'),
-      'AK' => t('Alaska'),
-      'AZ' => t('Arizona'),
-      'AR' => t('Arkansas'),
-      'CA' => t('California'),
-      'CO' => t('Colorado'),
-      'CT' => t('Connecticut'),
-      'DE' => t('Delaware'),
-      'DC' => t('District of Columbia'),
-      'FL' => t('Florida'),
-      'GA' => t('Georgia'),
-      'HI' => t('Hawaii'),
-      'ID' => t('Idaho'),
-      'IL' => t('Illinois'),
-      'IN' => t('Indiana'),
-      'IA' => t('Iowa'),
-      'KS' => t('Kansas'),
-      'KY' => t('Kentucky'),
-      'LA' => t('Louisiana'),
-      'ME' => t('Maine'),
-      'MD' => t('Maryland'),
-      'MA' => t('Massachusetts'),
-      'MI' => t('Michigan'),
-      'MN' => t('Minnesota'),
-      'MS' => t('Mississippi'),
-      'MO' => t('Missouri'),
-      'MY' => t('Montana'),
-      'NE' => t('Nebraska'),
-      'NV' => t('Nevada'),
-      'NH' => t('New Hampshire'),
-      'NJ' => t('New Jersey'),
-      'NM' => t('New Mexico'),
-      'NY' => t('New York'),
-      'NC' => t('North Carolina'),
-      'ND' => t('North Dakota'),
-      'OH' => t('Ohio'),
-      'OK' => t('Oklahoma'),
-      'OR' => t('Oregon'),
-      'PA' => t('Pennsylvania'),
-      'RI' => t('Rhode Island'),
-      'SC' => t('South Carolina'),
-      'SD' => t('South Dakota'),
-      'TN' => t('Tennessee'),
-      'TX' => t('Texas'),
-      'UT' => t('Utah'),
-      'VT' => t('Vermont'),
-      'VA' => t('Virginia'),
-      'WA' => t('Washington'),
-      'WV' => t('West Virginia'),
-      'WI' => t('Wisconsin'),
-      'WY' => t('Wyoming'),
-    )
-  );
-  $form['origin']['commerce_ups_postal_code'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Postal Code'),
-    '#size' => 5,
-    '#default_value' => variable_get('commerce_ups_postal_code')
-  );
-  $form['origin']['commerce_ups_country_code'] = array(
-    '#type' => 'select',
-    '#title' => t('Country'),
-    '#default_value' => variable_get('commerce_ups_country_code'),
-    '#options' => array(
-      '' => t('Please Select'),
-      'US' => t('United States of America'),
-    )
-  );
-  $form['services'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Enable UPS Shipping Services'),
-    '#collapsible' => TRUE,
-  );
-
-  $form['services']['commerce_ups_services'] = array(
-    '#type' => 'checkboxes',
-    '#options' => $array_options,
-    '#default_value' => variable_get('commerce_ups_services', array())
-  );
-  $form['packaging'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Enable UPS Packaging Types'),
-    '#collapsible' => FALSE,
-  );
-  $form['packaging']['commerce_ups_packaging_explanation'] = array(
-    '#type' => 'markup',
-    '#markup' => t('Only "Customer supplied packaging" is currently available. Please enter the package size below.'),
-  );
-  $form['packaging']['commerce_ups_packaging'] = array(
-    '#type' => 'hidden',
-    '#value' => '02',
-  );
-  /*
-  $form['packaging']['commerce_ups_packaging'] = array(
-    '#type' => 'checkboxes',
-    '#options' => _commerce_ups_packaging_types(),
-    '#default_value' => variable_get('commerce_ups_packaging', array())
-  );
-  */
-  // Fields for default package size (inches)
-  $form['default_package_size'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Package size (inches)'),
-    '#collapsible' => FALSE,
-    '#description' => 'UPS requires a package size when determining estimates.',
-  );
-  $form['default_package_size']['commerce_ups_default_package_size_length'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Length'),
-    '#size' => 5,
-    '#required' => TRUE,
-    '#default_value' => variable_get('commerce_ups_default_package_size_length'),
-  );
-  $form['default_package_size']['commerce_ups_default_package_size_width'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Width'),
-    '#size' => 5,
-    '#required' => TRUE,
-    '#default_value' => variable_get('commerce_ups_default_package_size_width'),
-  );
-  $form['default_package_size']['commerce_ups_default_package_size_height'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Height'),
-    '#size' => 5,
-    '#required' => TRUE,
-    '#default_value' => variable_get('commerce_ups_default_package_size_height'),
-  );
-  $form['default_package_size']['details'] = array(
-    '#markup' => 'The package size is used to determine the number of packages necessary to
-      create a UPS shipping cost estimate. <strong>If products do not have physical dimensions and
-      weights associated with them, the estimates will not be accurate.</strong> The logic implemented works as:
-      <ul>
-      <li>Assume each order requires at least one package.</li>
-      <li>Use the combined volume of all products in an order to determine the number of packages.</li>
-      </ul>
-      This is a simple calculation that can get close to actual shipping costs. More
-      complex logic involving multiple package sizes, weights, and void space can be implemented via
-      custom modules.
-      <br/><br/>
-      UPS has a ' . l('maximum package size', 'http://www.ups.com/content/us/en/resources/prepare/oversize.html', array('attributes' => array('target' => '_blank'))) . '.',
-  );
-  $form['commerce_ups_pick_up_schedule'] = array(
-    '#type' => 'select',
-    '#title' => t('Pick-up Schedule'),
-    '#default_value' => variable_get('commerce_ups_pick_up_schedule')
-  );
-  $form['commerce_ups_shipto_residential'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Calculate ALL ship to addresses as residential.'),
-    '#default_value' => variable_get('commerce_ups_shipto_residential', 0),
-  );
-  $form['commerce_ups_show_logo'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show UPS Logo on Shipping Page'),
-    '#default_value' => variable_get('commerce_ups_show_logo', 0),
-  );
-  $form['actions']['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save configuration'),
-  );
-  return $form;
-}
-
-/*
- * Implements hook_form_validate().
- */
-function shipping_matrix_ui_settings_form_validate($form, &$form_state) {
-  $values = $form_state['values'];
-  
-  // Ensure the default package size is less than the maximum (http://www.ups.com/content/us/en/resources/prepare/oversize.html)
-  //  Length (longest side) <= 108 inches
-  //  Girth = 2*width + 2*height
-  //  Length + Girth <= 165 inches
-  $dimensions = array($values['commerce_ups_default_package_size_length'],
-                      $values['commerce_ups_default_package_size_width'],
-                      $values['commerce_ups_default_package_size_height']);
-  sort($dimensions);
-  list($height, $width, $length) = $dimensions;
-  $girth = 2*$width + 2*$height;
-  if ($length > 108) {
-    form_set_error('commerce_ups_default_package_size_length', t('The greatest dimension of the package size must be 108 inches or less.'));
-  }
-  if ($length + $girth > 165) {
-    form_set_error('commerce_ups_default_package_size_length', t('The girth (2*width + 2*height) of the package size must be 165 inches or less.'));
-  }
-
-  $encrypted = variable_get('commerce_ups_encrypt', FALSE) && function_exists('aes_decrypt');
-
-  // If the Password field is empty, then they're not trying to update it and we should ignore it.
-  if (empty($values['commerce_ups_password'])) {
-    unset($form_state['values']['commerce_ups_password']);
-    if ($encrypted && empty($form_state['input']['commerce_ups_password'])) {
-      form_set_error('commerce_ups_password', t('You must enter in a password to turn off encryption.'));
-    }
-    return;
-  }
-  
-  /* If we are setting or resetting values, test the connection.
-  $ups_connection = ups_api_function_here();
-  if (is_good_connection($ups_connection)) {
-    drupal_set_message(t('Connection established. UPS credentials updated.'));
-  }
-  else {
-    drupal_set_message(
-      t('Resetting UPS credentials failed.'), 'error');
-    form_set_error('commerce_ups_account_id', t('Unable to connect to UPS. Please check your credentials.'));
-    form_set_error('commerce_ups_user_id');
-    form_set_error('commerce_ups_access_key');
-    form_set_error('commerce_ups_password');
-  }
-  */
-}
-
-/*
- * Implements hook_form_submit().
- */
-function shipping_matrix_ui_settings_form_submit($form, &$form_state) {
-  $encrypted = variable_get('commerce_ups_encrypt', FALSE) && function_exists('aes_decrypt');
-  // Encrypt the UPS API credentials if available
-  if (isset($form_state['input']['commerce_ups_encrypt']) && $form_state['input']['commerce_ups_encrypt']) {
-    $form_state['input']['commerce_ups_user_id'] = commerce_ups_encrypt($form_state['input']['commerce_ups_user_id']);
-    $form_state['input']['commerce_ups_account_id'] = commerce_ups_encrypt($form_state['input']['commerce_ups_account_id']);
-    $form_state['input']['commerce_ups_access_key'] = commerce_ups_encrypt($form_state['input']['commerce_ups_access_key']);
-    if (!empty($form_state['input']['commerce_ups_password'])) {
-      $form_state['input']['commerce_ups_password'] = commerce_ups_encrypt($form_state['input']['commerce_ups_password']);
-    }
-    elseif ($encrypted == FALSE) {
-      // This is an odd case, if encryption is turned on but the password is already in the db
-      // Then we need to pull it from the db, not from the field
-      $form_state['input']['commerce_ups_password'] = commerce_ups_encrypt(variable_get('commerce_ups_password', ''));
-    }
-  }
-
-  if (empty($form_state['input']['commerce_ups_password'])) {
-    unset($form_state['input']['commerce_ups_password']);
-  }
-
-  if (!isset($form_state['input']['commerce_ups_encrypt'])) {
-    $form_state['input']['commerce_ups_encrypt'] = FALSE;
-  }
-
-  $fields = array(
-    'commerce_ups_account_id',
-    'commerce_ups_user_id',
-    'commerce_ups_password',
-    'commerce_ups_access_key',
-    'commerce_ups_encrypt',
-    'commerce_ups_services',
-    'commerce_ups_company_name',
-    'commerce_ups_address_line_1',
-    'commerce_ups_address_line_2',
-    'commerce_ups_city',
-    'commerce_ups_state',
-    'commerce_ups_postal_code',
-    'commerce_ups_country_code',
-    'commerce_ups_packaging',
-    'commerce_ups_pick_up_schedule',
-    'commerce_ups_show_logo',
-    'commerce_ups_default_package_size_length',
-    'commerce_ups_default_package_size_width',
-    'commerce_ups_default_package_size_height',
-    'commerce_ups_shipto_residential',
-  );
-
-  foreach ($fields as $key) {
-    if (array_key_exists($key, $form_state['input'])) {
-      $value = $form_state['input'][$key];
-      variable_set($key, $value);
-    }
-  }
-
-  drupal_set_message(t('The UPS configuration options have been saved.'));
-}
diff --git a/modules/includes/shipping_matrix.shippingservice.inc b/modules/includes/shipping_matrix.shippingservice.inc
deleted file mode 100644
index cb98eef..0000000
--- a/modules/includes/shipping_matrix.shippingservice.inc
+++ /dev/null
@@ -1,201 +0,0 @@
-<?php
-/**
- * Returns a administration page for Matrix Shipping services.
- */
-function shipping_matrix_ui_shippingservice_admin_page() {
-  $content = array();
-  $content[] = array(
-    '#type' => 'item',
-    '#markup' => t('Administration page for Matrix Shipping Services.')
-  );
-  $content[] = array(
-    '#type' => 'item',
-    '#markup' => l(t('Add a Shipping Matrix Service'), 'admin/commerce/config/shipping/matrix/add'),
-  );
-  $content['table'] = shipping_matrix_ui_shippingservice_list_entities();
-
-  return $content;
-}
-
-/**
- * Returns a render array with all Matrix Shipping services.
- */
-function shipping_matrix_ui_shippingservice_list_entities() {
-  $content = array();
-
-  if (!user_access('administer shipping')) {
-    $content[] = array(
-      '#type' => 'item',
-      '#markup' => t('This user does not have permission to view entity_example_basic entities.'),
-    );
-    return $content;
-  }
-  // Load all shipping matrix shipping services.
-  
-	    $entities = shipping_matrix_ui_shippingservice_load_multiple();
-  
-  if (!empty($entities)) {
-  //drupal_set_message('<pre>'.print_r($entities, true).'</pre>');
-    foreach ( $entities as $entity ) {
-
-	// Set operations for this shipping service
-	 $ops[0] = array(
-	 'data' => array(
-	 	// edit link
-	 	'edit' => l(t('edit shipping service'), 'admin/commerce/config/shipping/matrix/' . $entity->shipping_service_id . '/edit'),
-		// go to zone overview link
-		'zone' => l(t('zone overview'), 'admin/commerce/config/shipping/matrix/' . $entity->shipping_service_id . '/zones'),
-		),
-	 'no_striping' => true
-		 );	
-	 $operations = array(
-      '#theme' => 'table',
-      '#rows' => $ops
-	   );
-  //drupal_set_message('<pre>'.print_r($operations, true).'</pre>');
-
-	
-      $rows[] = array(
-        'data' => array(
-          'id' => $entity->shipping_service_id,
-          'item_description' => l($entity->shipping_service_name, 
-		  	'admin/commerce/config/shipping/matrix/' . $entity->shipping_service_id),
-          'zones' => $entity->shipping_service_id,
-		  'default_rate' =>  isset($entity->shipping_matrix_price) ? 
-		  	commerce_currency_format($entity->shipping_matrix_price['und'][0]['amount'], $entity->shipping_matrix_price['und'][0]['currency_code']) : '',
-		  'max_dimensions' =>  isset($entity->shipping_matrix_dimensions) ? 
-		  	physical_dimensions_format($entity->shipping_matrix_dimensions['und'][0]) : '',
-		  'max_weight' =>  isset($entity->shipping_matrix_weight) ? 
-		  	physical_weight_format($entity->shipping_matrix_weight['und'][0]) : '',
-		  'operations' =>  drupal_render($operations),
-        ),
-      );
-    }
-    $content['entity_table'] = array(
-      '#theme' => 'table',
-      '#rows' => $rows,
-      '#header' => array(t('ID'), t('Shipping Service'), t('Zones'), t('Basic Shipping Rate'), t('Max Dimensions'), t('Max Weight'), t('Opperations')),
-    );
-  }
-  else {
-    $content[] = array(
-      '#type' => 'item',
-      '#markup' => t('No Matrix Shipping Service currently exist.'),
-    );
-  }
-  return $content;
-}
-
-function shipping_matrix_ui_shippingservice_load_multiple($basic_ids = FALSE, $conditions = array(), $reset = FALSE) {
-  return entity_load('shipping_matrix_services', $basic_ids, $conditions, $reset);
-}
-
-
-/**
- * Provides a wrapper on the edit form to add a new entity.
- */
-function shipping_matrix_ui_shippingservice_add() {
-  // Create a basic entity structure to be used and passed to the validation
-  // and submission functions.
-  $entity = entity_get_controller('shipping_matrix_services')->create();
-  return drupal_get_form('shipping_matrix_ui_shippingservice_form', $entity);
-}
-
-/**
- * Form function to create an entity_example_basic entity.
- *
- * The pattern is:
- * - Set up the form for the data that is specific to your
- *   entity: the columns of your base table.
- * - Call on the Field API to pull in the form elements
- *   for fields attached to the entity.
- */
-function shipping_matrix_ui_shippingservice_form($form, &$form_state, $entity) {
-  // load entity by id, if entity is passed as id
-  if(!is_object($entity) && ctype_digit($entity)) { 
-	  $entities = shipping_matrix_ui_shippingservice_load_multiple(array($entity));
-	  $entity = $entities[$entity];
-	  }  
-  //drupal_set_message('<pre>'.print_r($entity, true).'</pre>');
-
-  $form['shipping_service_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Shipping Service Name'),
-    '#required' => TRUE,
-    '#default_value' => !empty($entity->shipping_service_name) ? $entity->shipping_service_name : '',
-  );
-  $form['shipping_service_description'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Shipping Service Description'),
-    '#required' => false,
-    '#default_value' => !empty($entity->shipping_service_description) ? $entity->shipping_service_description : '',
-  );
-  
-  //load entity in form
-  $form['basic_entity'] = array(
-    '#type' => 'value',
-    '#value' => $entity,
-  );
-  // attach fields by this entity
-  field_attach_form('shipping_matrix_services', $entity, $form, $form_state);
-  
-  // attach buttons to this form
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-    '#weight' => 100,
-  );
-  $form['delete'] = array(
-    '#type' => 'submit',
-    '#value' => t('Delete'),
-    '#submit' => array('shipping_matrix_ui_shippingservice_delete'),
-    '#weight' => 200,
-  );
-
-  return $form;
-}
-
-
-/**
- * Validation handler for entity_example_basic_add_form form.
- * We pass things straight through to the Field API to handle validation
- * of the attached fields.
- */
-function shipping_matrix_ui_shippingservice_form_validate($form, &$form_state) {
-  //field_attach_form_validate('shipping_matrix_ui_shippingservice', $form_state['values']['basic_entity'], $form, $form_state);
-}
-
-
-/**
- * Form submit handler: submits basic_add_form information
- */
-function shipping_matrix_ui_shippingservice_form_submit($form, &$form_state) {
-  $entity = $form_state['values']['basic_entity'];
-  $entity->shipping_service_name = $form_state['values']['shipping_service_name'];
-  $entity->shipping_service_description = $form_state['values']['shipping_service_description'];
-  field_attach_submit('shipping_matrix_services', $entity, $form, $form_state);
-  drupal_set_message("Submitted");
-  $entity = shipping_matrix_ui_shippingservice_save($entity);
-  $form_state['redirect'] = 'admin/commerce/config/shipping/matrix';
-  }
-
-function shipping_matrix_ui_shippingservice_save(&$entity) {
-  return entity_get_controller('shipping_matrix_services')->save($entity);
-  }
-
-/**
- * Delete function for form submit
- */
-function shipping_matrix_ui_shippingservice_delete($form, &$form_state) {
-  $entity = $form_state['values']['basic_entity'];
-  $entity = shipping_matrix_ui_shippingservice_del($entity);
-  drupal_set_message("Shipping service deleted");
-  $form_state['redirect'] = 'admin/commerce/config/shipping/matrix';
-  }
-
-/**
- * Delete shipping service entity
- */
-function shipping_matrix_ui_shippingservice_del(&$entity) {
-  return entity_get_controller('shipping_matrix_services')->delete($entity);
-  }
\ No newline at end of file
diff --git a/modules/includes/shipping_matrix.zones.inc b/modules/includes/shipping_matrix.zones.inc
deleted file mode 100644
index eb94827..0000000
--- a/modules/includes/shipping_matrix.zones.inc
+++ /dev/null
@@ -1,219 +0,0 @@
-<?php
-
-
-/**
- * Returns a administration page for Matrix shipping zones.
- */
-function shipping_matrix_ui_zones_admin_page($shippingService) {
-  $content = array();
-  $content[] = array(
-    '#type' => 'item',
-    '#markup' => t('Administration page for Matrix shipping zones.')
-  );
-  $content[] = array(
-    '#type' => 'item',
-    '#markup' => l(t('Add a Zone to this Shipping Matrix Service'), 'admin/commerce/config/shipping/matrix/'.$shippingService.'/zones/add'),
-  );
-  $content['table'] = shipping_matrix_ui_zones_list_entities($shippingService);
-
-  return $content;
-}
-
-/**
- * Returns a render array with all Matrix shipping zones.
- */
-function shipping_matrix_ui_zones_list_entities($shippingService) {
-  $content = array();
-
-  if (!user_access('administer shipping')) {
-    $content[] = array(
-      '#type' => 'item',
-      '#markup' => t('This user does not have permission to view entity_example_basic entities.'),
-    );
-    return $content;
-  }
-  // Load all shipping matrix shipping zones.
-  
-  $query = new EntityFieldQuery();
-  $entities = $query->entityCondition('entity_type', 'shipping_matrix_zone')
-                    //->entityCondition('bundle', 'shipping_matrix_zone')
-                    ->propertyCondition('shipping_zone_shipping_service_id', $shippingService)
-                    //->fieldCondition('field_date', 'value', array('2011-03-01', '2011-03-31'), 'BETWEEN')
-                    //->fieldOrderBy('field_date', 'value', 'ASC')
-                    ->execute();
- //drupal_set_message('<pre>'.print_r($entities, true).'</pre>');
-  if (!empty($entities)) {
-  $entities = shipping_matrix_ui_zones_load_multiple(array_keys($entities['shipping_matrix_zone']));
-  
-  	
-    foreach ( $entities as $entity ) {
-		
-	// Set operations for this shipping service
-	 $ops[0] = array(
-	 'data' => array(
-	 	// edit link
-	 	'edit' => l(t('edit this zone'), 'admin/commerce/config/shipping/matrix/'.$shippingService.'/zones/' . $entity->shipping_zone_id . '/edit'),
-		// go to zone overview link
-		'zone' => l(t('edit shipping weight table'), 'admin/commerce/config/shipping/matrix/'.$shippingService.'/zones/' . $entity->shipping_zone_id . '/table'),
-		),
-	 'no_striping' => true
-		 );	
-	 $operations = array(
-      '#theme' => 'table',
-      '#rows' => $ops
-	   );
-		
-		
-      $rows[] = array(
-        'data' => array(
-          'id' => $entity->shipping_zone_id,
-          'item_description' => l($entity->shipping_zone_name, 
-		  	'admin/commerce/config/shipping/matrix/' . $entity->shipping_zone_id),
-          'zones' => $entity->shipping_zone_id,
-		  'default_rate' =>  isset($entity->shipping_base_shipping_price) ? 
-		  	commerce_currency_format($entity->shipping_base_shipping_price['und'][0]['amount'], $entity->shipping_base_shipping_price['und'][0]['currency_code']) : '',
-		  'max_dimensions' =>  isset($entity->shipping_max_shipping_dimensions) ? 
-		  	physical_dimensions_format($entity->shipping_max_shipping_dimensions['und'][0]) : '',
-		  'max_weight' =>  isset($entity->shipping_max_shipping_weight) ? 
-		  	physical_weight_format($entity->shipping_max_shipping_weight['und'][0]) : '',
-		  'operations' => drupal_render($operations), 
-        ),
-      );
-    }
-    $content['entity_table'] = array(
-      '#theme' => 'table',
-      '#rows' => $rows,
-      '#header' => array(t('ID'), t('shipping zone'), t('Zones'), t('Basic Shipping Rate'), t('Max Dimensions'), t('Max Weight'), t('Opperations')),
-    );
-  }
-  else {
-    $content[] = array(
-      '#type' => 'item',
-      '#markup' => t('No Matrix shipping zone currently exist.'),
-    );
-  }
-  return $content;
-}
-
-function shipping_matrix_ui_zones_load_multiple($basic_ids = FALSE, $conditions = array(), $reset = FALSE) {
-  return entity_load('shipping_matrix_zone', $basic_ids, $conditions, $reset);
-}
-
-
-/**
- * Provides a wrapper on the edit form to add a new entity.
- */
-function shipping_matrix_ui_zones_add($shippingservice) {
-  // Create a basic entity structure to be used and passed to the validation
-  // and submission functions.
-  $entity = entity_get_controller('shipping_matrix_zone')->create();
-  return drupal_get_form('shipping_matrix_ui_zones_form', $entity, $shippingservice);
-}
-
-/**
- * Form function to create an entity_example_basic entity.
- *
- * The pattern is:
- * - Set up the form for the data that is specific to your
- *   entity: the columns of your base table.
- * - Call on the Field API to pull in the form elements
- *   for fields attached to the entity.
- */
-function shipping_matrix_ui_zones_form($form, &$form_state, $entity, $shippingservice) {
-  // load entity by id, if entity is passed as id
-  if(!is_object($entity) && ctype_digit($entity)) { 
-	  $entities = shipping_matrix_ui_zones_load_multiple(array($entity));
-	  $entity = $entities[$entity];
-	  }  
-  //drupal_set_message('<pre>'.print_r($entity, true).'</pre>');
-
-  $form['shipping_zone_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('shipping zone Name'),
-    '#required' => TRUE,
-    '#default_value' => !empty($entity->shipping_zone_name) ? $entity->shipping_zone_name : '',
-  );
-  $form['shipping_service'] = array(
-    '#type' => 'hidden',
-    '#value' => $shippingservice,
-  );
-
-/*
-  $form['shipping_zone_description'] = array(
-    '#type' => 'textfield',
-    '#title' => t('shipping zone Description'),
-    '#required' => false,
-    '#default_value' => !empty($entity->shipping_service_description) ? $entity->shipping_service_description : '',
-  );
-*/
-  
-  //load entity in form
-  $form['basic_entity'] = array(
-    '#type' => 'value',
-    '#value' => $entity,
-  );
-  // attach fields by this entity
-  field_attach_form('shipping_matrix_zone', $entity, $form, $form_state);
-  
-  // attach buttons to this form
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save'),
-    '#weight' => 100,
-  );
-  $form['delete'] = array(
-    '#type' => 'submit',
-    '#value' => t('Delete'),
-    '#submit' => array('shipping_matrix_zones_delete'),
-    '#weight' => 200,
-  );
-
-  return $form;
-}
-
-
-/**
- * Validation handler for entity_example_basic_add_form form.
- * We pass things straight through to the Field API to handle validation
- * of the attached fields.
- */
-function shipping_matrix_ui_zones_form_validate($form, &$form_state) {
-  //field_attach_form_validate('shipping_matrix_zones', $form_state['values']['basic_entity'], $form, $form_state);
-}
-
-
-/**
- * Form submit handler: submits basic_add_form information
- */
-function shipping_matrix_ui_zones_form_submit($form, &$form_state) {
-  $entity = $form_state['values']['basic_entity'];
-  $entity->shipping_zone_name = $form_state['values']['shipping_zone_name'];
-  $entity->	shipping_zone_shipping_service_id = $form_state['values']['shipping_service'];
-
-  //$entity->shipping_service_description = $form_state['values']['shipping_service_description'];
-  field_attach_submit('shipping_matrix_zone', $entity, $form, $form_state);
-  drupal_set_message("Submitted");
-  $entity = shipping_matrix_ui_zones_save($entity);
-  $form_state['redirect'] = 'admin/commerce/config/shipping/matrix/'.$form_state['values']['shipping_service'].'/zones';
-  }
-
-function shipping_matrix_ui_zones_save(&$entity) {
-  return entity_get_controller('shipping_matrix_zone')->save($entity);
-  }
-
-/**
- * Delete function for form submit
- */
-function shipping_matrix_ui_zones_delete($form, &$form_state) {
-  $entity = $form_state['values']['basic_entity'];
-  $entity = shipping_matrix_ui_zones_del($entity);
-  drupal_set_message("shipping zone deleted");
-  $form_state['redirect'] = 'admin/commerce/config/shipping/matrix';
-  }
-
-/**
- * Delete shipping zone entity
- */
-function shipping_matrix_ui_zones_del(&$entity) {
-  return entity_get_controller('shipping_matrix_zone')->delete($entity);
-  }
\ No newline at end of file
diff --git a/modules/shipping_matrix_ui.info b/modules/shipping_matrix_ui.info
deleted file mode 100644
index f0da496..0000000
--- a/modules/shipping_matrix_ui.info
+++ /dev/null
@@ -1,7 +0,0 @@
-name = Shipping Matrix UI
-description = Provides a UI for the Shipping Matrix method.
-package = Commerce (shipping)
-dependencies[] = shipping_matrix
-core = 7.x
-
-
diff --git a/modules/shipping_matrix_ui.module b/modules/shipping_matrix_ui.module
deleted file mode 100644
index d3fb411..0000000
--- a/modules/shipping_matrix_ui.module
+++ /dev/null
@@ -1,143 +0,0 @@
-<?php
-
-/**
- * @file
- * Takes care of the UI for the shipping matrix
- */
-
-function shipping_matrix_ui_menu() {
-  $items = array();
-    $items['admin/commerce/config/shipping/matrix'] = array(
-    'title' => 'Administer Shipping Matrix',
-    'page callback' => 'shipping_matrix_ui_shippingservice_admin_page',
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.shippingservice.inc',
-  );
-  // 'Edit' tab for shipping services.
-  $items['admin/commerce/config/shipping/matrix/%/edit'] = array(
-    'title' => 'Shipping Service',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('shipping_matrix_ui_shippingservice_form', 5),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.shippingservice.inc',
-  );
-  // Add Shipping service.
-  $items['admin/commerce/config/shipping/matrix/add'] = array(
-    'title' => 'Add a Shipping Matrix Shipping Service',
-    'page callback' => 'shipping_matrix_ui_shippingservice_add',
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.shippingservice.inc',
-  );
-   // 'Zones' tab for adding zones to shipping services.
-  $items['admin/commerce/config/shipping/matrix/%/zones'] = array(
-    'title' => 'Zones',
-    'page callback' => 'shipping_matrix_ui_zones_admin_page',
-    'page arguments' => array(5),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.zones.inc',
-  );
-   // Add a Zones to a shipping service.
-  $items['admin/commerce/config/shipping/matrix/%/zones/add'] = array(
-    'title' => 'Add Zone',
-    'page callback' => 'shipping_matrix_ui_zones_add',
-    'page arguments' => array(5),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.zones.inc',
-  );
-   // Add a Zones to a shipping service.
-  $items['admin/commerce/config/shipping/matrix/%/zones/%/edit'] = array(
-    'title' => 'Edit Zone',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('shipping_matrix_ui_zones_form', 7, 5),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.zones.inc',
-  );
-
-   // Add a Zones to a shipping service.
-  $items['admin/commerce/config/shipping/matrix/%/zones/%/table'] = array(
-    'title' => 'Weight Table',
-    'page callback' => 'shipping_matrix_ui_weight_table_admin_page',
-    'page arguments' => array(7, 5),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.weighttable.inc',
-  );
-
-   // Add a Zones to a shipping service.
-  $items['admin/commerce/config/shipping/matrix/%/zones/%/add'] = array(
-    'title' => 'Add Weight Table row',
-    'page callback' => 'shipping_matrix_ui_weight_table_add',
-    'page arguments' => array(5, 7),
-    'access arguments' => array('administer shipping'),
-	'file' => 'includes/shipping_matrix.weighttable.inc',
-  );
-
-   // Add a Ajax for deleting.
-  $items['shipping_matrix/ajax'] = array(
-    'title' => 'Remove item callback',
-    'page callback' => 'shipping_matrix_ui_remove_js',
-    'delivery callback' => 'ajax_deliver',
-    'access callback' => TRUE,
-    'theme callback' => 'ajax_base_page_theme',
-    'type' => MENU_CALLBACK,
-    'file path' => 'includes',
-    'file' => 'form.inc',
-  );
-
-  return $items;
-  }
-
-
-function shipping_matrix_ui_remove_js() {
-  // drupal_html_id() very helpfully ensures that all html IDS are unique
-  // on a page. Unfortunately what it doesn't realize is that the IDs
-  // we are generating are going to replace IDs that already exist, so
-  // this actually works against us.
-  if (isset($_POST['ajax_html_ids'])) {
-    unset($_POST['ajax_html_ids']);
-  }
-
-  list($form, $form_state) = ajax_get_form();
-  drupal_process_form($form['#form_id'], $form, $form_state);
-
-  // Get the information on what we're removing.
-  $button = $form_state['triggering_element'];
-  // Go two levels up in the form, to the whole widget.
-  $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -3));
-  // Now send back the proper AJAX command to replace it.
-  $return = array(
-    '#type' => 'ajax',
-    '#commands' => array(
-      ajax_command_replace('#' . $element['#id'], drupal_render($element))
-    ),
-  );
-
-  // Because we're doing this ourselves, messages aren't automatic. We have
-  // to add them.
-  $messages = theme('status_messages');
-  if ($messages) {
-    $return['#commands'][] = ajax_command_prepend('#' . $element['#id'], $messages);
-  }
-
-  return $return;
-  }
-
-
-/**
- * Make some changes to forms.
- */
-function shipping_matrix_ui_form_alter(&$form, $form_state, $form_id)  {
-  switch ($form_id)  {
-	// Delete name and street blocks
-	// name and street are not considerd as zones	
-	case 'shipping_matrix_ui_zones_form':	
-	  foreach($form['shipping_matrix_locality']['und'] as $localkey => $locality){
-		if(is_int($localkey)) { 
-		  // delete the name field from form
-		  unset($form['shipping_matrix_locality']['und'][$localkey]['name_block']);
-		  // delete the address fields form form.
-		  unset($form['shipping_matrix_locality']['und'][$localkey]['street_block']);
-		  }
-		}
-	  break;
-	}
-  }
\ No newline at end of file
diff --git a/shipping_matrix.controllers.inc b/shipping_matrix.controllers.inc
deleted file mode 100644
index be10530..0000000
--- a/shipping_matrix.controllers.inc
+++ /dev/null
@@ -1,391 +0,0 @@
-<?php
-
-/**
- * ShippingMatrixShippingServiceControllerInterface definition.
- *
- * We create an interface here because anyone could come along and
- * use hook_entity_info_alter() to change our controller class.
- * We want to let them know what methods our class needs in order
- * to function with the rest of the module, so here's a handy list.
- *
- * @see hook_entity_info_alter()
- */
-
-interface ShippingMatrixShippingServiceControllerInterface
-  extends DrupalEntityControllerInterface {
-  public function create();
-  public function save($entity);
-  public function delete($entity);
-}
-
-/**
- * EntityExampleBasicController extends DrupalDefaultEntityController.
- *
- * Our subclass of DrupalDefaultEntityController lets us add a few
- * important create, update, and delete methods.
- */
-class ShippingMatrixShippingServiceController
-  extends DrupalDefaultEntityController
-  implements ShippingMatrixShippingServiceControllerInterface {
-
-  /**
-   * Create and return a new entity_example_basic entity.
-   */
-  public function create() {
-    $entity = new stdClass();
-    $entity->type = 'shipping_matrix_services';
-    $entity->bundle_type = 'shipping_matrix_services';
-	$entity->is_new = TRUE;
-	//$entity->shipping_service_id = false;
-    $entity->item_description = '';
-    return $entity;
-  }
-
-  /**
-   * Saves the custom fields using drupal_write_record()
-   */
-  public function save($entity) {
-	//drupal_set_message("Save entity in controler is called");
-    //drupal_set_message('<pre>'.print_r($entity, true).'</pre>');
-
-    // If our entity has no basic_id, then we need to give it a
-    // time of creation.
-    // Invoke hook_entity_presave().
-    module_invoke_all('entity_presave', 'shipping_matrix_services', $entity);
-    // The 'primary_keys' argument determines whether this will be an insert
-    // or an update. So if the entity already has an ID, we'll specify
-    // basic_id as the key.
-	$primary_keys = NULL;
-    if(isset($entity->shipping_service_id)) { 
-	$primary_keys = $entity->shipping_service_id ? 'shipping_service_id' : array();
-	}
-	
-    // Write out the entity record.
-	// table to write to, entity data to write to table, primairy key
-    drupal_write_record('shipping_matrix_shipping_service', $entity, $primary_keys);
-    // We're going to invoke either hook_entity_update() or
-    // hook_entity_insert(), depending on whether or not this is a
-    // new entity. We'll just store the name of hook_entity_insert()
-    // and change it if we need to.
-    $invocation = 'entity_insert';
-    // Now we need to either insert or update the fields which are
-    // attached to this entity. We use the same primary_keys logic
-    // to determine whether to update or insert, and which hook we
-    // need to invoke.
-	
-
-    if (empty($primary_keys)) {
-      field_attach_insert('shipping_matrix_services', $entity);
-    }
-    else {
-      field_attach_update('shipping_matrix_services', $entity);
-      $invocation = 'entity_update';
-    }
-    // Invoke either hook_entity_update() or hook_entity_insert().
-    module_invoke_all($invocation, 'shipping_matrix_services', $entity);
-    return $entity;
-  }
-
-  /**
-   * Delete a single entity.
-   *
-   * Really a convenience function for delete_multiple().
-   */
-  public function delete($entity) {
-    $this->delete_multiple(array($entity));
-  }
-
-  /**
-   * Delete one or more entity_example_basic entities.
-   *
-   * Deletion is unfortunately not supported in the base
-   * DrupalDefaultEntityController class.
-   *
-   * @param $basic_ids
-   *   An array of entity IDs or a single numeric ID.
-   */
-  public function delete_multiple($entities) {
-    $shipping_service_id = array();
-    if (!empty($entities)) {
-      $transaction = db_transaction();
-      try {
-        foreach ($entities as $entity) {
-          module_invoke_all('shipping_matrix_services_delete', $entity);
-          // Invoke hook_entity_delete().
-          module_invoke_all('entity_delete', $entity, 'shipping_matrix_shippingservice');
-          field_attach_delete('shipping_matrix_services', $entity);
-          $shipping_service_id[] = $entity->shipping_service_id;
-        }
-        db_delete('shipping_matrix_shipping_service')
-          ->condition('shipping_service_id', $shipping_service_id, 'IN')
-          ->execute();
-
-      }
-      catch (Exception $e) {
-        $transaction->rollback();
-        watchdog_exception('shipping_matrix', $e);
-        throw $e;
-      }
-    }
-  }
-}
-
-
-//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-/**
- * ShippingMatrixZonesControllerInterface definition.
- *
- * We create an interface here because anyone could come along and
- * use hook_entity_info_alter() to change our controller class.
- * We want to let them know what methods our class needs in order
- * to function with the rest of the module, so here's a handy list.
- *
- * @see hook_entity_info_alter()
- */
-
-interface ShippingMatrixZonesControllerInterface
-  extends DrupalEntityControllerInterface {
-  public function create();
-  public function save($entity);
-  public function delete($entity);
-}
-
-/**
- * EntityExampleBasicController extends DrupalDefaultEntityController.
- *
- * Our subclass of DrupalDefaultEntityController lets us add a few
- * important create, update, and delete methods.
- */
-class ShippingMatrixZonesController
-  extends DrupalDefaultEntityController
-  implements ShippingMatrixZonesControllerInterface {
-
-  /**
-   * Create and return a new entity_example_basic entity.
-   */
-  public function create() {
-    $entity = new stdClass();
-    $entity->type = 'shipping_matrix_zone';
-    $entity->shipping_zone_id = 0;
-    $entity->bundle_type = 'shipping_matrix_zone';
-    $entity->item_description = '';
-    return $entity;
-  }
-
-  /**
-   * Saves the custom fields using drupal_write_record()
-   */
-  public function save($entity) {
-	drupal_set_message("Save entity in controler is called");
-    drupal_set_message('<pre>'.print_r($entity, true).'</pre>');
-
-    // If our entity has no basic_id, then we need to give it a
-    // time of creation.
-    if (empty($entity->shipping_zone_id)) {
-      $entity->created = time();
-    }
-    // Invoke hook_entity_presave().
-    module_invoke_all('entity_presave', 'shipping_matrix_zone', $entity);
-    // The 'primary_keys' argument determines whether this will be an insert
-    // or an update. So if the entity already has an ID, we'll specify
-    // basic_id as the key.
-    $primary_keys = $entity->shipping_zone_id ? 'shipping_zone_id' : array();
-    // Write out the entity record.
-    drupal_write_record('shipping_matrix_shipping_zone', $entity, $primary_keys);
-    // We're going to invoke either hook_entity_update() or
-    // hook_entity_insert(), depending on whether or not this is a
-    // new entity. We'll just store the name of hook_entity_insert()
-    // and change it if we need to.
-    $invocation = 'entity_insert';
-    // Now we need to either insert or update the fields which are
-    // attached to this entity. We use the same primary_keys logic
-    // to determine whether to update or insert, and which hook we
-    // need to invoke.
-    if (empty($primary_keys)) {
-      field_attach_insert('shipping_matrix_zone', $entity);
-    }
-    else {
-      field_attach_update('shipping_matrix_zone', $entity);
-      $invocation = 'entity_update';
-    }
-    // Invoke either hook_entity_update() or hook_entity_insert().
-    module_invoke_all($invocation, 'shipping_matrix_zone', $entity);
-    return $entity;
-  }
-
-  /**
-   * Delete a single entity.
-   *
-   * Really a convenience function for delete_multiple().
-   */
-  public function delete($entity) {
-    $this->delete_multiple(array($entity));
-  }
-
-  /**
-   * Delete one or more entity_example_basic entities.
-   *
-   * Deletion is unfortunately not supported in the base
-   * DrupalDefaultEntityController class.
-   *
-   * @param $basic_ids
-   *   An array of entity IDs or a single numeric ID.
-   */
-  public function delete_multiple($entities) {
-    $shipping_zone_id = array();
-    if (!empty($entities)) {
-      $transaction = db_transaction();
-      try {
-        foreach ($entities as $entity) {
-          module_invoke_all('shipping_matrix_zone_delete', $entity);
-          // Invoke hook_entity_delete().
-          module_invoke_all('entity_delete', $entity, 'shipping_matrix_zone');
-          field_attach_delete('shipping_matrix_zone', $entity);
-          $shipping_zone_id[] = $entity->shipping_zone_id;
-        }
-        db_delete('shipping_matrix_zone')
-          ->condition('basic_id', $shipping_zone_id, 'IN')
-          ->execute();
-
-      }
-      catch (Exception $e) {
-        $transaction->rollback();
-        watchdog_exception('shipping_matrix', $e);
-        throw $e;
-      }
-    }
-  }
-}
-
-
-//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-
-
-/**
- * ShippingMatrixTableWeightControllerInterface definition.
- *
- * We create an interface here because anyone could come along and
- * use hook_entity_info_alter() to change our controller class.
- * We want to let them know what methods our class needs in order
- * to function with the rest of the module, so here's a handy list.
- *
- * @see hook_entity_info_alter()
- */
-
-interface ShippingMatrixTableWeightControllerInterface
-  extends DrupalEntityControllerInterface {
-  public function create();
-  public function save($entity);
-  public function delete($entity);
-}
-
-/**
- * EntityExampleBasicController extends DrupalDefaultEntityController.
- *
- * Our subclass of DrupalDefaultEntityController lets us add a few
- * important create, update, and delete methods.
- */
-class ShippingMatrixTableWeightController
-  extends DrupalDefaultEntityController
-  implements ShippingMatrixTableWeightControllerInterface {
-
-  /**
-   * Create and return a new entity_example_basic entity.
-   */
-  public function create() {
-    $entity = new stdClass();
-    $entity->type = 'shipping_matrix_weight_table';
-    $entity->weight_table_id = 0;
-    $entity->bundle_type = 'shipping_matrix_weight_table';
-    $entity->item_description = '';
-    return $entity;
-  }
-
-  /**
-   * Saves the custom fields using drupal_write_record()
-   */
-  public function save($entity) {
-	drupal_set_message("Save entity in controler is called");
-    drupal_set_message('<pre>'.print_r($entity, true).'</pre>');
-
-    // If our entity has no basic_id, then we need to give it a
-    // time of creation.
-    // Invoke hook_entity_presave().
-    module_invoke_all('entity_presave', 'shipping_matrix_weight_table', $entity);
-    // The 'primary_keys' argument determines whether this will be an insert
-    // or an update. So if the entity already has an ID, we'll specify
-    // basic_id as the key.
-    $primary_keys = $entity->weight_table_id ? 'weight_table_id' : array();
-    // Write out the entity record.
-    drupal_write_record('shipping_matrix_weight_table', $entity, $primary_keys);
-    // We're going to invoke either hook_entity_update() or
-    // hook_entity_insert(), depending on whether or not this is a
-    // new entity. We'll just store the name of hook_entity_insert()
-    // and change it if we need to.
-    $invocation = 'entity_insert';
-    // Now we need to either insert or update the fields which are
-    // attached to this entity. We use the same primary_keys logic
-    // to determine whether to update or insert, and which hook we
-    // need to invoke.
-    if (empty($primary_keys)) {
-      field_attach_insert('shipping_matrix_weight_table', $entity);
-    }
-    else {
-      field_attach_update('shipping_matrix_weight_table', $entity);
-      $invocation = 'entity_update';
-    }
-    // Invoke either hook_entity_update() or hook_entity_insert().
-    module_invoke_all($invocation, 'shipping_matrix_weight_table', $entity);
-    return $entity;
-  }
-
-  /**
-   * Delete a single entity.
-   *
-   * Really a convenience function for delete_multiple().
-   */
-  public function delete($entity) {
-    $this->delete_multiple(array($entity));
-  }
-
-  /**
-   * Delete one or more entity_example_basic entities.
-   *
-   * Deletion is unfortunately not supported in the base
-   * DrupalDefaultEntityController class.
-   *
-   * @param $basic_ids
-   *   An array of entity IDs or a single numeric ID.
-   */
-  public function delete_multiple($entities) {
-    $weight_table_id = array();
-    if (!empty($entities)) {
-      $transaction = db_transaction();
-      try {
-        foreach ($entities as $entity) {
-          module_invoke_all('shipping_matrix_weight_table_delete', $entity);
-          // Invoke hook_entity_delete().
-          module_invoke_all('entity_delete', $entity, 'shipping_matrix_weight_table');
-          field_attach_delete('shipping_matrix_weight_table', $entity);
-          $weight_table_id[] = $entity->weight_table_id;
-        }
-        db_delete('shipping_matrix_weight_table')
-          ->condition('weight_table_id', $weight_table_id, 'IN')
-          ->execute();
-
-      }
-      catch (Exception $e) {
-        $transaction->rollback();
-        watchdog_exception('shipping_matrix', $e);
-        throw $e;
-      }
-    }
-  }
-}
-
-
-//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-
-
diff --git a/shipping_matrix.info b/shipping_matrix.info
deleted file mode 100644
index 330952c..0000000
--- a/shipping_matrix.info
+++ /dev/null
@@ -1,11 +0,0 @@
-name = Shipping Matrix
-description = Provides a weight and country based shipping method.
-package = Commerce (shipping)
-dependencies[] = commerce
-dependencies[] = physical
-dependencies[] = commerce_physical
-dependencies[] = commerce_shipping
-
-core = 7.x
-
-
diff --git a/shipping_matrix.install b/shipping_matrix.install
deleted file mode 100644
index 701fc9a..0000000
--- a/shipping_matrix.install
+++ /dev/null
@@ -1,506 +0,0 @@
-<?php
-
-/**
- * @file
- * Handles installation for Shipping Matrix module.
- */
-
-/**
- * implements hook_schema()
- *
- */
- 
-function shipping_matrix_schema() { 
-  
-  $schema['shipping_matrix_shipping_service'] = array(
-	'description' => 'This table holds the shipping services',
-	'fields' => array(
-	  'shipping_service_id' => array(
-		'description' => 'the unique identifier for the shipping service',
-		'type' => 'serial',
-		'not null' => TRUE,
-	  ),
-	  'shipping_service_name' => array(
-		'description' => 'The name of the shipping service',
-		'type' => 'varchar',
-		'length' => '255',
-		'not null' => TRUE,
-	  ),
-	  'shipping_service_description' => array(
-		'description' => 'Description of the shipping service',
-		'type' => 'text',
-		'not null' => TRUE,
-	  ),
-	),
-	'primary key' => array('shipping_service_id'),
-  );
-  
-  $schema['shipping_matrix_shipping_zone'] = array(
-	'description' => 'Table with zones belonging to a shipping service',
-	'fields' => array(
-	  'shipping_zone_id' => array(
-		'description' => 'The unique identifier of the zone',
-		'type' => 'serial',
-		'not null' => TRUE,
-	  ),
-	  'shipping_zone_shipping_service_id' => array(
-		'description' => 'The shipping service this zone belongs to.',
-		'type' => 'int',
-		'not null' => TRUE,
-	  ),
-	  'shipping_zone_name' => array(
-		'description' => 'The name of the Zone',
-		'type' => 'varchar',
-		'length' => '255',
-		'not null' => TRUE,
-	  ),
-	),
-	'primary key' => array('shipping_zone_id', 'shipping_zone_shipping_service_id'),
-  );
-  
-  $schema['shipping_matrix_weight_table'] = array(
-	'description' => 'This table holds the price per weight',
-	'fields' => array(
-	  'weight_table_id' => array(
-		'description' => 'unique identifier for this row',
-		'type' => 'serial',
-		'not null' => TRUE,
-	  ),
-	  'weight_table_zone_id' => array(
-		'description' => 'The zone id this weight belongs to',
-		'type' => 'int',
-		'not null' => TRUE,
-	  ),
-	),
-	'primary key' => array('weight_table_id', 'weight_table_zone_id'),
-  );
-  
- 
-
- return $schema;
-
-} 
-
-
-
-/**
- * Implements hook_install().
- */
-
-function shipping_matrix_install() {
-  //install database tables
-  // drupal_install_schema('shipping_matrix');
-  
-  // Create all the fields we are adding to our content type.
-  // http://api.drupal.org/api/function/field_create_field/7
-  foreach (_shipping_matrix_installed_fields() as $field) {
-	field_create_field($field);
-  }
-  
-  // Create all the instances for our fields.
-  // http://api.drupal.org/api/function/field_create_instance/7
-  // attach fields to: shipping_matrix_services
-  foreach (_shipping_matrix_installed_instances() as $ikey => $instance) {
-	$instance['entity_type'] = 'shipping_matrix_services';
-	$instance['bundle'] = 'shipping_matrix_services';
-	if(in_array($ikey, array(
-	  'shipping_matrix_max_dimensions', 
-	  'shipping_matrix_max_shipping_weight', 
-	  'shipping_matrix_base_price', 
-	  ))){
-		  	//drupal_set_message('<pre> instance: shipping_matrix_services: '. print_r($instance, true) . '</pre>');
-
-		field_create_instance($instance);
-	  }
-	}  
-  // attach fields to: shipping_matrix_zone
-  foreach (_shipping_matrix_installed_instances() as $ikey => $instance) {
-	$instance['entity_type'] = 'shipping_matrix_zone';
-	$instance['bundle'] = 'shipping_matrix_zone';
-
-	  if(in_array($ikey, array(
-	  'shipping_matrix_max_shipping_weight',
-	  'shipping_matrix_base_price', 
-	  'shipping_matrix_zone_locality', 
-	  ))){
-		  	//drupal_set_message('<pre> instance: shipping_matrix_zone: '. print_r($instance, true) . '</pre>');
-
-		field_create_instance($instance);
-	  }
-	}
-  // attach fields to: shipping_matrix_weight_table
-  foreach (_shipping_matrix_installed_instances() as $ikey => $instance) {
-	$instance['entity_type'] = 'shipping_matrix_weight_table';
-	$instance['bundle'] = 'shipping_matrix_weight_table';
-	  if(in_array($ikey, array(
-	  'shipping_matrix_weight_price', 
-	  'shipping_matrix_net_shipping_weight', 
-	  'shipping_matrix_gross_shipping_weight', 
-	  ))){
-		  	drupal_set_message('<pre> instance: shipping_matrix_weight_table'. print_r($instance, true) . '</pre>');
-
-		field_create_instance($instance);
-	  }
-	}
-	 
-  }
-
-/**
- * Implements hook_uninstall().
- */
-function shipping_matrix_uninstall() {
-
-	
-//delete fields
-  $fields = array(
-    'shipping_matrix_services',
-  );
-
-  foreach ($fields as $data) {
-    variable_del($data);
-  }
-  
-  // uninstall database tables
-  drupal_uninstall_schema('shipping_matrix');  
-  
- // Loop over each of the fields defined by this module and delete
-  // all instances of the field, their data, and the field itself.
-  // http://api.drupal.org/api/function/field_delete_field/7
-  foreach (array_keys(_shipping_matrix_installed_fields()) as $field) {
-    field_delete_field($field);
-  }
-
-  // Loop over any remaining field instances attached to the node_example
-  // content type (such as the body field) and delete them individually.
-  // http://api.drupal.org/api/function/field_delete_field/7
-  foreach (_shipping_matrix_installed_instances() as $instance_name => $instance) {
-    field_delete_instance($instance);
-  }
-  
-  
-}
-
-
-/**
- * Returns a structured array defining the fields created by this content type.
- *
- * This is factored into this function so it can be used in both
- * shipping_matrix_install() and shipping_matrix_uninstall().
- *
- * @return
- *  An associative array specifying the fields we wish to add to our
- *  new entity type.
- *
- */
-
-
-function _shipping_matrix_installed_fields() {
-  $t = get_t();
-  return array(
-    'shipping_matrix_dimensions' => array(
-      'field_name'  => 'shipping_matrix_dimensions',
-      'cardinality' => 1,
-      'type'        => 'physical_dimensions',
-    ),
-    'shipping_matrix_weight' => array(
-      'field_name'  => 'shipping_matrix_weight',
-      'cardinality' => 1,
-      'type'        => 'physical_weight',
-    ),
-    'shipping_matrix_weight_gross' => array(
-      'field_name'  => 'shipping_matrix_weight_gross',
-      'cardinality' => 1,
-      'type'        => 'physical_weight',
-    ),
-    'shipping_matrix_price' => array(
-      'field_name'  => 'shipping_matrix_price',
-      'cardinality' => 1,
-      'type'        => 'commerce_price',
-    ),
-    'shipping_matrix_locality' => array(
-      'field_name'  => 'shipping_matrix_locality',
-      'cardinality' => -1,
-      'type'        => 'addressfield',
-    ),
-
-  );
-}
-
-/**
- * Returns a structured array defining the instances for this entity.
- *
- * The instance lets Drupal know which widget to use to allow the user to enter
- * data and how to react in different view modes.  
- *
- * This is factored into this function so it can be used in both
- * joinprofile_install() and joinprofile_uninstall().
- *
- * @return
- *  An associative array specifying the instances we wish to add to our new
- *  node type.
- *
- */
-function _shipping_matrix_installed_instances() {
-  $t = get_t();
-  return array(
-   'shipping_matrix_max_dimensions' => array(
-      'field_name'  => 'shipping_matrix_dimensions',
-      'label' => $t('Maximum shipping dimensions'),
-      'type' => 'physical_dimensions',
-      'required' => FALSE,
-	  'widget' => array (
-		'weight' => '10',
-		'type' => 'physical_dimensions_textfields',
-		'module' => 'physical',
-		'active' => 1,
-		'settings' => array (
-		  'default_unit' => 'mm',
-		  'unit_select_list' => 1,
-		),
-	  ),
-	  'display' => array (
-		'default' => array (
-		  'label' => 'above',
-		  'type' => 'physical_dimensions_formatted',
-		  'settings' => array (),
-		  'module' => 'physical',
-		  'weight' => 1,
-		),
-	  ),
-	  'description' => '',
-	  'default_value' => NULL,
-    ),
-
-   'shipping_matrix_max_shipping_weight' => array(
-      'field_name' => 'shipping_matrix_weight',
-      'label' => $t('Maximum shipping weight'),
-      'type' => 'physical_weight',
-      'required' => FALSE,
-	  'widget' => array (
-		'weight' => '8',
-		'type' => 'physical_weight_textfield',
-		'module' => 'physical',
-		'active' => 1,
-		'settings' => array (
-		  'default_unit' => 'g',
-		  'unit_select_list' => 1,
-		),
-	  ),
-	 'display' => array (
-		'default' => array (
-		  'label' => 'above',
-		  'type' => 'physical_weight_formatted',
-		  'settings' => array (),
-		  'module' => 'physical',
-		  'weight' => 2,
-		),
-	  ),
-    ),
-
-
-   'shipping_matrix_net_shipping_weight' => array(
-      'field_name' => 'shipping_matrix_weight',
-      'label' => $t('Net shipping weight'),
-      'type' => 'physical_weight',
-      'required' => TRUE,
-	  'widget' => array (
-		'weight' => '8',
-		'type' => 'physical_weight_textfield',
-		'module' => 'physical',
-		'active' => 1,
-		'settings' => array (
-		  'default_unit' => 'g',
-		  'unit_select_list' => 1,
-		),
-	  ),
-	 'display' => array (
-		'default' => array (
-		  'label' => 'above',
-		  'type' => 'physical_weight_formatted',
-		  'settings' => array (),
-		  'module' => 'physical',
-		  'weight' => 2,
-		),
-	  ),
-    ),
-
-   'shipping_matrix_gross_shipping_weight' => array(
-      'field_name' => 'shipping_matrix_weight_gross',
-      'label' => $t('Gross shipping weight'),
-      'type' => 'physical_weight',
-      'required' => FALSE,
-	  'widget' => array (
-		'weight' => '8',
-		'type' => 'physical_weight_textfield',
-		'module' => 'physical',
-		'active' => 1,
-		'settings' => array (
-		  'default_unit' => 'g',
-		  'unit_select_list' => 1,
-		),
-	  ),
-	 'display' => array (
-		'default' => array (
-		  'label' => 'above',
-		  'type' => 'physical_weight_formatted',
-		  'settings' => array (),
-		  'module' => 'physical',
-		  'weight' => 2,
-		),
-	  ),
-    ),
-
-   'shipping_matrix_base_price' => array(
-      'field_name' => 'shipping_matrix_price',
-      'label' => $t('Base shipping costs'),
-      'type' => 'commerce_price',
-      'required' => FALSE,
-	  'widget' => array (
-		'type' => 'commerce_price_full',
-		'weight' => 6,
-		'settings' => array (
-		  'currency_code' => 'default',
-		),
-		'module' => 'commerce_price',
-	  ),
-	  'display' => array (
-		'display' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-		'default' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-		'node_teaser' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-	  ),
-	  'description' => '',
-      ),
-
-   'shipping_matrix_weight_price' => array(
-      'field_name' => 'shipping_matrix_price',
-      'label' => $t('Weight based shipping costs'),
-      'type' => 'commerce_price',
-      'required' => TRUE,
-	  'widget' => array (
-		'type' => 'commerce_price_full',
-		'weight' => 6,
-		'settings' => array (
-		  'currency_code' => 'default',
-		),
-		'module' => 'commerce_price',
-	  ),
-	  'display' => array (
-		'display' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-		'default' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-		'node_teaser' => array (
-		  'label' => 'hidden',
-		  'type' => 'commerce_price_formatted_amount',
-		  'settings' => array (
-			'calculation' => false,
-		  ),
-		  'weight' => 0,
-		  'module' => 'commerce_price',
-		),
-	  ),
-	  'description' => '',
-      ),
-
-	'shipping_matrix_zone_locality' => array (
-	  'field_name' => 'shipping_matrix_locality',
-      'label' => $t('Zone locality'),
-      'type' => 'addressfield',
-	  'label' => 'Address',
-	  'required' => false,
-	  'widget' => array (
-		'type' => 'addressfield_standard',
-		'weight' => 12,
-		'settings' => array (
-		  'format_handlers' => array (
-			0 => 'address',
-			1 => 'name-oneline',
-		  ),
-		  'available_countries' => array (),
-		),
-		'module' => 'addressfield',
-	  ),
-	  'display' => array (
-		'default' => array (
-		  'label' => 'hidden',
-		  'type' => 'addressfield_default',
-		  'weight' => -10,
-		  'settings' => array (
-			'use_widget_handlers' => 1,
-			'format_handlers' => array (
-			  0 => 'address',
-			),
-		  ),
-		  'module' => 'addressfield',
-		),
-		'customer' => array (
-		  'label' => 'hidden',
-		  'type' => 'addressfield_default',
-		  'weight' => -10,
-		  'settings' => array (
-			'use_widget_handlers' => 1,
-			'format_handlers' => array (
-			  0 => 'address',
-			),
-		  ),
-		  'module' => 'addressfield',
-		),
-		'administrator' => array (
-		  'label' => 'hidden',
-		  'type' => 'addressfield_default',
-		  'weight' => -10,
-		  'settings' => array (
-			'use_widget_handlers' => 1,
-			'format_handlers' => array (
-			  0 => 'address',
-			),
-		  ),
-		  'module' => 'addressfield',
-		),
-	  ),
-	  'settings' => array (
-		'user_register_form' => false,
-	  ),
-	  'description' => '',
-	),  
-	
-  );
-}
diff --git a/shipping_matrix.module b/shipping_matrix.module
deleted file mode 100644
index 9bc735f..0000000
--- a/shipping_matrix.module
+++ /dev/null
@@ -1,486 +0,0 @@
-<?php
-/**
- * @file
- * Defines an shipping method for shipping by weight and country.
- */
-
-
-// include entity controlers
-include_once('/shipping_matrix.controllers.inc');
-
-/**
- * Implements hook_menu().
- */
-function shipping_matrix_menu() {
-  $items = array();
-  return $items;
-  }
-
-
-/**
- * Implements hook_commerce_shipping_method_info().
- */
-function shipping_matrix_commerce_shipping_method_info() {
-  $shipping_methods = array();
-
-  $shipping_methods['shipping_matrix'] = array(
-    'title' => t('Shipping Matrix'),
-    'description' => t('Shipping quote from shipping matrix.'),
-  );
-
-  return $shipping_methods;
-}
-
-/**
- * Implements hook_commerce_shipping_service_info().
- */
-function shipping_matrix_commerce_shipping_service_info() {
-  $shipping_services = array();
-  $available_services = _shipping_matrix_service_list();
-  $selected_services = variable_get('shipping_matrix_services', array());
-  foreach ($available_services as $id => $val) {
-    if ($val != 0) { // if you find a selected one...
-      $service = $available_services[$id];
-      $shipping_services[$service['slug']] = array(
-        'title' => t($service['title']),
-        'description' => t($service['description']),
-        'display_title' => t($service['title']),
-        'shipping_method' => 'shipping_matrix',
-        'price_component' => 'shipping',
-        'callbacks' => array(
-          'rate' => 'shipping_matrix_service_rate',
-          //'details_form' => 'shipping_matrix_service_details_form',
-	      //'details_form_validate' => 'shipping_matrix_service_details_form_validate',
-    	  //'details_form_submit' => 'shipping_matrix_service_details_form_submit',
-        ),
-      );
-
-    }
-  }
-  return $shipping_services;
-  }
-
-
-/**
- * function to get the created services services.
- */
-function _shipping_matrix_service_list() {
-  $list = entity_load('shipping_matrix_services');
-  $services =  array();
-  foreach($list as $key => $service) {
-	$services[$service->shipping_service_id] = array(
-	  'shipping_service_id' => $service->shipping_service_id,
-	  'title' => t($service->shipping_service_name), 
-	  'description' => t($service->shipping_service_description));
-	}
-  /* Make a unique ID to identify the service by */
-  foreach ($services as $key => $service) {
-	$service['slug'] = 'shipping_matrix_service_id_'.$service['shipping_service_id'];
-	$services[$key] = $service;
-	}  
-  return $services;
-  }
-
-
-
-/**
- * Shipping service callback: returns a base price array for a shipping service
- * calculated for the given order.
- */
-function shipping_matrix_service_rate($shipping_service, $order) {
-  // Get the id number of the shipping service
-  $shipping_service = _shipping_matrix_get_shipping_service($shipping_service);
-  // Get the shipping service information
-  $query = new EntityFieldQuery();	
-  $query->entityCondition('entity_type', 'shipping_matrix_services')
-		->propertyCondition('shipping_service_id', $shipping_service);
-  $result = $query->execute();
-  
-  // load matrix services
-  if (isset($result['shipping_matrix_services'])) {
-	$shipping_matrix_services_nids = array_keys($result['shipping_matrix_services']);
-	$shipping_matrix_services = entity_load('shipping_matrix_services', $shipping_matrix_services_nids);
-	}
-  #drupal_set_message('<pre> shipping service:'.print_r($shipping_matrix_services, true).'</pre>');
-
-  reset($shipping_matrix_services); //Safety - sets pointer to top of array
-  $key = key($shipping_matrix_services); // Returns the first key of it
-
-  
-  // get base price for this shipping service.
-  $shipping_matrix_price = $shipping_matrix_services[$key]->shipping_matrix_price['und'][0]; 
-  #drupal_set_message('<pre> price of this shipping service:'.print_r($shipping_matrix_price, true).'</pre>');
-  // get max weight for this shipping service
-  $max_weight = $shipping_matrix_services[$key]->shipping_matrix_weight['und'][0]; 
-
-  // get max dimension for this shipping service
-  $outerbox = $shipping_matrix_services[$key]->shipping_matrix_dimensions['und'][0]; 
-
-  //@TODO remove this when fitting script is finished.
-  $innerbox['length'] = 250.00000;
-  $innerbox['width'] = 25.00000;
-  $innerbox['height'] = 370.00000;
-  $innerbox['unit'] = 'mm';
-  
-  // first check if service supports the weights:
-  if(shipping_matrix_order_items_weight($max_weight, $order)) {
-	#drupal_set_message('<pre> Order has items to ship and weight is smaller than max:'.print_r($max_weight, true).'</pre>');
-	$order_has_weight = true;
-	// @TODO: next check if the contents fit in the package.
-	// Need to make a loop function for every order and check vor physical field, if found, compare with this function. 
-	if(shipping_matrix_fits_dimension($outerbox, $innerbox)) {
-	  #drupal_set_message('<pre> Order has items that will fit in the shipping container, outerbox:'.print_r($outerbox, true).' innerbox: '.print_r($innerbox, true).' </pre>');
-	  $order_can_be_packed = true;
-	  }
-  	}
-
-  // if both conditions are met, we go and calculate the costs.
-  if($order_has_weight && $order_can_be_packed) {
-	$totalprice = array();
-	// get the cheapest zone 
-	//@TODO Maybe some sort options, cheapest ASC DESC, zone name ASC DESC, zone id ASC DESC?
-	
-	// use shipping service as base currency
-	// setup componets to calculate total.
-	$components = $shipping_matrix_price;
-	$components['data']['components'][]['price'] = $shipping_matrix_price;
-	
-	$zone_costs = _shipping_matrix_get_zone_cost($shipping_service, $order);
-	// if zone has no costs then zone and service is not applicable.
-	if($zone_costs['amount'] <= 0) {
-		 return false;
-	}
-	$components['data']['components'][]['price']  = $zone_costs;
-	$shippingcosts = commerce_price_component_total($components);
-  	}		
-
-  if($shippingcosts['amount'] > 0) {
-	#drupal_set_message('<pre> shippingcosts larger:'.print_r($shippingcosts, true).'</pre>');
-	return array(
-	  'amount' => $shippingcosts['amount'],
-	  'currency_code' => $shippingcosts['currency_code'],
-	  'data' => $shippingcosts['data'],
-	  );
-	}
-  return false;
-  }
-
-// function for retreiving the shipping service id
-function _shipping_matrix_get_shipping_service($service) {
-  return str_replace('shipping_matrix_service_id_', '', $service['base']);
-}
-
-
-// function for retreiving the shipping country of an order
-function _shipping_matrix_get_country($order){
-  foreach ($order->commerce_customer_shipping['und'] as $profile_ref) {
-  	$profile_ids[] = $profile_ref['profile_id'];
-  	}
-  //load the profiles
-  $profiles = commerce_customer_profile_load_multiple($profile_ids);
-  reset($profiles); //Safety - sets pointer to top of array
-  $key = key($profiles); // Returns the first key of it
-
-  drupal_set_message('<pre>'.print_r( $profiles[$key]->commerce_customer_address['und'][0]['country'] , true).'</pre>');
-  return $profiles[$key]->commerce_customer_address['und'][0]['country'];
-}
-
-
-function _shipping_matrix_get_orderweight($order, $unit = 'g'){
-  // loop over order and retreive order weights.
-  $weight = commerce_physical_order_weight($order, $unit);
-  return $weight;
-}
-
-
-// function for retreiving the zones that are available for a country
-function _shipping_matrix_get_zone_cost($service_id, $order){
-  // We need to make sure all calculataions in weight are in the same unit.
-  // So we setup a standard unit, i have chosen for grams.
-  $unit = 'g';
-  $components = array();
-
-  //@todo needs to change in addressfield... for comparing against other address fields
-  $country = _shipping_matrix_get_country($order);	
-    
-  // Total order weight.
-  $total_order_weight = _shipping_matrix_get_orderweight($order, $unit);
-	
-  // Get the zone information
-  //@todo change field condition to addressfield	
-  $query = new EntityFieldQuery();	
-  $query->entityCondition('entity_type', 'shipping_matrix_zone')
-		->propertyCondition('shipping_zone_shipping_service_id', $service_id)
-		->fieldCondition('shipping_matrix_locality', 'country', $country, '=');
-  $result = $query->execute();
-  // get zone entity
-  if (isset($result['shipping_matrix_zone'])) {
-	$shipping_matrix_zone_nids = array_keys($result['shipping_matrix_zone']);
-	$shipping_matrix_zone = entity_load('shipping_matrix_zone', $shipping_matrix_zone_nids);
-  
-  reset($shipping_matrix_zone); //Safety - sets pointer to top of array
-  $key = key($shipping_matrix_zone); // Returns the first key of it
-
-  
-  #drupal_set_message('<pre> Zone : '.print_r($shipping_matrix_zone, true).'</pre>');
-
-  
-  
-  // Calculate price zone
-  $components = $shipping_matrix_zone[$key]->shipping_matrix_price['und'][0];
-  $components['data']['components'][]['price'] = $shipping_matrix_zone[$key]->shipping_matrix_price['und'][0];
-  drupal_set_message('<pre> Zone costs: '.print_r($shipping_matrix_zone[$key]->shipping_matrix_price, true).'</pre>');
-  //Get the table weight quote
-  
-  //@TODO: add sorting support multi currency!! 
-  $query = new EntityFieldQuery();	
-  $query->entityCondition('entity_type', 'shipping_matrix_weight_table')
-		->propertyCondition('weight_table_zone_id', $shipping_matrix_zone[$key]->shipping_zone_id)
-		->fieldOrderBy('shipping_matrix_price', 'amount', 'ASC');
-  
-  $result = $query->execute();
-  
-  if (isset($result['shipping_matrix_weight_table'])) {
-	$shipping_matrix_weight_table_nids = array_keys($result['shipping_matrix_weight_table']);
-	$shipping_matrix_weight_table = entity_load('shipping_matrix_weight_table', $shipping_matrix_weight_table_nids);
-	
-	foreach($shipping_matrix_weight_table as $row => $weightoption) { 
-	  $tableweight_net = physical_weight_convert($weightoption->shipping_matrix_weight['und'][0], $unit);
-	  $tableweight_gross = physical_weight_convert($weightoption->shipping_matrix_weight_gross['und'][0], $unit);
-		// unset the not applicable table weights
-		if($tableweight_net['weight'] < $total_order_weight['weight'] ) {
-			unset($shipping_matrix_weight_table[$row]);
-		}
-	  }
-	// ok now we have the list with available table quotes.
-	// we sorted the array on price amount
-	// now take the cheapest tableweight as price.
-	foreach($shipping_matrix_weight_table as $row => $weightoption) { 
-	  $tableweight = $weightoption;
-	  break;
-	  }
-	//add weight table price component to total
-	$components['data']['components'][]['price']  = $tableweight->shipping_matrix_price['und'][0];
-
-	drupal_set_message('<pre> Table weight costs: '.print_r($tableweight->shipping_matrix_price, true).'</pre>');
-
-	}
-  }
-
-	//combine all components to one price
-	$zone_total = commerce_price_component_total($components);
-  
-	drupal_set_message('<pre> Total Zone costs: '.print_r($zone_total, true).'</pre>');
-	// return total price amount.
-	return $zone_total;
-  }
-
-
-/**
- * Determines the weight of an entire order.
- *
- * @param $max_weight
- *   A weight field value array representing the total weight of a package in this service
- * @param $order
- *   The order object whose weight value should be calculated.
- * @param $unit
- *   The unit of measurement to use for the returned weight of the order.
- *
- * @return
- *   true if all items of 
- *   the specified unit of measurement or NULL if no weight could be determined.
- */
-
-
-function shipping_matrix_order_items_weight($max_weight, $order, $unit = 'g') {
-  $max_weight = physical_weight_convert($max_weight, $unit);
-  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
-  // var to check if at leas one items has weight
-  $ihm = false;
-  // var to check if all items are smaller than the max weight
-  $smw = true;
-  // Loop over each line item on the order.
-  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
-    // Get the weight value of product line items.
-    if (in_array($line_item_wrapper->type->value(), commerce_product_line_item_types())) {
-      $line_item_weight = commerce_physical_product_line_item_weight($line_item_wrapper->value());
-      // Add it to the running total converting it to the required weight unit.
-      if (!empty($line_item_weight['weight'])) {
-		  $ihm = true;
-        $converted_weight = physical_weight_convert($line_item_weight, $unit);
-		#drupal_set_message($max_weight['weight'] . ' < ' . $converted_weight['weight']);
-		if($max_weight['weight'] < $converted_weight['weight']){
-			$smw = false;
-		}
-      }
-    }
-  }
- // both needs to be true, at least one item has to have weight applied to it, and all items needs to be smallerd than the max allowed in a package.
- if($ihm === true &&  $smw == true){
-  return true;
-  }
- return false; 
- }
-
-/**
- * Checks if a box fits in another box.
- *
- * @param $outerbox
- *   A dimension field value array including the 'length', 'width', 'height' and
- *   'unit'.
- * @param $innerbox
- *   A dimension field value array including the 'length', 'width', 'height' and
- *   'unit'.
- *
- * @return
- *   True is the innerbox fits inside the outerbox
- */
-function shipping_matrix_fits_dimension($outerbox, $innerbox, $unit = 'mm') { 
-	
-  // Convert dimensions to mm
-  $outerbox = physical_dimensions_convert($outerbox, $unit);
-  $innerbox = physical_dimensions_convert($innerbox, $unit);
-  
-  // Class to check if box fits in box
-  require_once('shipping_matrix.binpacking.inc');
-  $binpack = new boxing();
-  $binpack -> add_outer_box($outerbox['length'],$outerbox['width'],$outerbox['height']); // our quantum box; l, w, h
-  $binpack -> add_inner_box($innerbox['length'],$innerbox['width'],$innerbox['height']); // schroedingers cat; l, w, h
-  
-  // if box fits in box return true
-  try {
-	 //@TODO undefined notice 
-	 // suppres error for now
-	if (@$binpack -> fits()) return true;
-  }  
-  catch (Exception $e) {
-	watchdog_exception($e);
-	}
-
-	return false;
-}
-
-
-/**
- * Shipping service callback: returns the example shipping service details form.
- */
-function shipping_matrix_service_details_form($pane_form, $pane_values, $checkout_pane, $order, $shipping_service) {
-  $form = array();
-
-  $pane_values['service_details'] += array(
-    'name' => '',
-    'express' => '',
-  );
-
-  $form['name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Name'),
-    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
-    '#default_value' => $pane_values['service_details']['name'],
-    '#required' => TRUE,
-  );
-
-  $form['express'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Express delivery'),
-    '#description' => t('Express delivery (costs an additional $15)'),
-    '#default_value' => $pane_values['service_details']['express'],
-  );
-
-  return $form;
-}
-
-/**
- * Shipping service callback: validates the example shipping service details.
- */
-function shipping_matrix_service_details_form_validate($details_form, $details_values, $shipping_service, $order, $form_parents) {
-  if (strlen($details_values['name']) < 2) {
-    form_set_error(implode('][', array_merge($form_parents, array('name'))), t('You must enter a name two or more characters long.'));
-
-    // Even though the form error is enough to stop the submission of the form,
-    // it's not enough to stop it from a Commerce standpoint because of the
-    // combined validation / submission going on per-pane in the checkout form.
-    return FALSE;
-  }
-}
-
-/**
- * Shipping service callback: increases the shipping line item's unit price if
- * express delivery was selected.
- */
-function shipping_matrix_service_details_form_submit($details_form, $details_values, $line_item) {
-  if ($details_values['express']) {
-    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
-
-    // Build a price array for the express delivery fee.
-    $express_price = array(
-      'amount' => 1500,
-      'currency_code' => 'USD',
-      'data' => array(),
-    );
-
-  }
-}
-
-/**
- * Implements hook_commerce_price_component_type_info().
- */
-function shipping_matrix_commerce_price_component_type_info() {
-  return array(
-    'example_shipping_service_express' => array(
-      'title' => t('Express delivery'),
-      'weight' => 20,
-    ),
-  );
-}
-
-/**
- * Implements hook_entity_info().
- */
-
-function shipping_matrix_entity_info() {
-  return array(
-    'shipping_matrix_services' => array(
-      'label' => t('Shipping Matrix Shipping Service'),
-      'base table' => 'shipping_matrix_shipping_service',
-      'entity keys' => array(
-        'id' => 'shipping_service_id',
-      ),
-	  'fieldable' => TRUE,
-	  'controller class' => 'ShippingMatrixShippingServiceController',
-
-    ),
-	'shipping_matrix_zone' => array(
-      'label' => t('Shipping Matrix Zone'),
-      'base table' => 'shipping_matrix_shipping_zone',
-      'entity keys' => array(
-        'id' => 'shipping_zone_id',
-      ),
-	  'fieldable' => TRUE,
-  	  'controller class' => 'ShippingMatrixZonesController',
-
-    ),
-	'shipping_matrix_weight_table' => array(
-      'label' => t('Shipping Matrix Weight Table'),
-      'base table' => 'shipping_matrix_weight_table',
-      'entity keys' => array(
-        'id' => 'weight_table_id',
-      ),
-	  'fieldable' => TRUE,
-   	  'controller class' => 'ShippingMatrixTableWeightController',
-
-    ),
-
-  );
-}
-
-/**
- * Implementation of hook_flush_caches().
- *
- * This tells Drupal's cache handling system the name of our caching 
- * table, so expired items will be purged automatically and this table 
- * also affected by the empty all caches function.
- */
-function shipping_matrix_flush_caches() {
- // return array('cache_shipping_matrix_country_zone', 'cache_shipping_matrix_shipping_service', 'cache_shipping_matrix_shipping_zone', 'cache_shipping_matrix_weight_table',);
-}
\ No newline at end of file
