Solid mechanics in colloidal and bacterial filtration